1. 12

  2. 5

    I must be the only person ever who would want the reverse: C for C++ users. I honestly find C a lot weirder than C++.

    Due to a curious historical accident, in 1998 the AP Board (a US high school educational thing) decided to use C++ for a single year to teach AP Computer Science. Normally they go with Pascal, Java and I think right now it’s Python. But for one glorious year, they decided to go with C++. So that was my first “real” programming language, i.e. the first I learned in a classroom setting. This means I really did learn C++ without knowing C.

    This makes me a feel a bit different from nearly everyone else who considers C to be the foundation and is baffled by C++.

    1. 5

      Really to get to C from C++ you mostly just have to remove features. I’m curious what specific confusions you’ve run into that such a guide could cover?

      1. 1

        I don’t understand memcpy, malloc, free, strcpy, strncpy.These are not functions you use in C++. Why do I have to do struct foo x; if foo is a struct type instead of just doing foo x;?.The general syntax for structs is really weird in C. You have to typedef, you can’t just declare new structs? And I can’t declare looping variables, I have to instead declare it outside the loop. Ah, and no single-line coments, // is not a valid comment starter. What’s with all the pointers? We don’t use nearly that many pointers in C++. Arrays are confusing as shit. I always forget when do arrays become pointers and when do they not. Why is there no actual array type?

        I think newer versions of C have made some of these things more like C++, but you still run into a lot of C that has to be written in an older way. C is just very foreign if you use C++.

        1. [Comment removed by author]

          1. 1

            I think I already understand most of these things, but what I was trying to convey was that C is foreign, not so much looking for an explanation.

            It is entirely possible to know C++ and find C to be weird and foreign.

          2. 1

            I’ll try to summarize these.

            memcpy, malloc, free, strcpy – the best source for these is their manpages, which are generally well-written

            You do not use typedef to define structs in C (though some people confusingly choose to add a typedef as well). The name of the type is struct foo so that’s why you say struct foo x to declare variable.

            The reason C89 doesn’t allow variable declaration in for loop is for consistency (new things can only be added to the stack after an open brace) – there was no one “right way” semantic for the special case – however C99 dispensed with this so it’s the same as C++ now.

            Single line comments weren’t in C89 probably because no one thought having two comment syntaxes would be easier than just having one. C99 added the second one if you prefer it.

            All the C++ I’ve ever seen is still full of pointers – do you routinely pass full object instances on the stack? Anytime you say new in C++ you have created a pointer.

            Arrays in C are always “converted” to pointers when used in a value context. Declared arrays have their own semantics for sizeof, etc (since they are of “array type”). In arguments, int x[] is just sugar for int *x

            Hopefully those are helpful.

            1. 1

              Arrays are confusing as shit. I always forget when do arrays become pointers and when do they not. Why is there no actual array type?


              1. 1

                That still confuses me. I always need to refer to this document which I always forget.


                Btw, I wasn’t looking for an explanation. I was trying to impress upon you how weird and foreign C is for a C++ person. I can look up these explanations, but C will always be weird and foreign to me because I was raised on C++.

          3. 2

            I went from Pascal straight to C++. My parents happened to buy me Stroustrup’s C++ book. I only had to learn to read C later as I started encountering C libraries.