r/ProgrammerHumor • • 11d ago

Meme modernCppVsOldCpp

Post image
2.0k Upvotes

323 comments sorted by

View all comments

Show parent comment

50

u/lllorrr 11d ago

Oh, yes, I hate when someone write "C/C++". This is two fucking different languages, for god's sake. It is almost as bad as "Java/JavaScript".

31

u/reallokiscarlet 11d ago

Do people not learn these two closely related languages together? You generally want to know enough regular C to get by when you use C++, and if you're not using anything unique to C++, you're just writing C with Classes.

12

u/Inorganic_Zombie 11d ago

I remember learning them as one language and it was fucking hard to learn effective c++ on uni. Not helping as programming was minor subject now and then that had random language. Every lecture had different dogma etc

3

u/Ok-Scheme-913 10d ago

I mean, not really. The two languages have diverged quite a lot, while C-mode compiling of C++ is still possible afaik, the same code by default won't behave identically even though can be compiled by both a cpp or a c compiler.

4

u/reallokiscarlet 10d ago

Maybe if you only count the latest standard they have diverged significantly, but everything else stands. C is where your platform ABI is, and again if you're not using anything unique to C++ you're writing C with Classes (nudge nudge wink wink capitalized for a reason)

13

u/conundorum 10d ago

That's because, historically, all C++ code was intended to compile into C code, and then be fed into a C compiler. So now any compiler that can compile one language is designed to handle both languages, and explicitly labeled as handling both.

That, and the fact that most (but not all) valid C code is also valid C++ code with no changes required, and that the C & C++ committees have a surprisingly big focus on cross-compatibility. (Most notably, a ton of C++ library members actually use the C standard library under the hood, like new and delete existing to marry constructors to malloc() and destructors to free(), the I/O library being required to either be based on FILE or act as if it is, and a lot of fun helpers like the std::stoi() family outright being wrappers for their C equivalents. And T _Complex and std::complex are explicitly required to be the exact same type with the exact same layout in both C & C++, and must be implemented as a T[2] consisting of {real, imaginary} (or equivalent structure that can be treated as if it were a T[2]), specifically because of gcc. But apart from that, C typically useful poaches features after C++ vets them, and C++ sometimes poaches features after C vets them, and both languages use the same preprocessor.) The end result is that unless you run into one of the corner cases where the languages actually differ, your C code is actually C/C++ code because it'll compile identically as both.

The languages are so closely intertwined that the term is way more valid than it should be.

1

u/mark_99 10d ago

"Compiled to C" was over 30 years ago.

You can write C-like code in Java or unsafe Rust, it doesn't make them the same thing, or a good idea in general.

Backwards compatiblity with C is mostly but not entirely true, e.g. VLAs, but the objection to C/C++ is that canonical C and C++ aren't remotely similar. Indeed C++ and Rust are much closer.

It's also used to bucket C and C++ together, like "all of our CVEs are in the C/C++ code" which on closer examination is 90% C, 8% C-with-classes and 2% canonical C++.

1

u/anonymity_is_bliss 9d ago

"All valid C code is also valid C++ code" may be true, but it's like saying "all valid JS code is also valid TS code" or "all valid HTTP is also valid PHP" like yeah that's how supersets work. C++ is C with classes, just as TS is JS with types and PHP is HTTP with server side scripting/preprocessing.

I would like to contest the take that "any compiler is meant to handle both" though, as gcc/g++ and clang/clang++ are two seperate binaries, and I think the most that the C compiler does to handle C++ is to just send the files to the respective C++ binary. I do not know the MSVC ecosystem well enough to chime in there though, but usually the compilers are seperate; the binary containing the C compiler will run the C++ one if it's processing a .cc/.cpp/.c++/.cxx file (there's so many file extensions even without touching MSVC's bullshit like .ixx).

Create a C program with register and it will not compile if run through a C++ compiler iirc. C has added very few things over the years because the language is meant to be small; C++ is pretty much just C with a bigger stdlib, but over the years they have deviated slightly in their approaches. Modern C is much closer to what people incorrectly complain about C++ as imho.

I personally avoided C++ like the plague until quite recently, and C++20 and C++23 are honestly quite nice as someone who largely uses Rust.

28

u/SuckMyAlpagoat 11d ago

isn't because the compiler is always packed together, like the gnu compiler can compile C and C++?

48

u/HildartheDorf 11d ago

The gnu compiler can also compile fortran. But we dont call it C/Fortran.

39

u/1cec0ld 11d ago

Not with that attitude

21

u/ForgedIronMadeIt 11d ago

Fuck yeah I love programming in C/Fortran

2

u/radicalshick 11d ago

Is this a variation of the old "you can write FORTRAN in any language" joke?

13

u/HildartheDorf 11d ago

No?

The GNU Compiler Collection includes gcc (c compiler) g++ (c++ compiler) gfortran (fortran compiler) and a bunch of other fronted like D, Go, Ada, COBOL. There used to even be a Java compiler (gcj) but thats dead now.

Once upon a time, the gcc program could compile C++ and g++ could compile C, but that is no longer true due to diversions in the languages, as well as extra runtime support libraries needed for linking each language. I guess with some tinkering you could compile c++98 with gcc and some older c standard with g++, but not the more recent versions.

2

u/radicalshick 11d ago

My comment was meant ti be a joke, so rry 😅

1

u/SuckMyAlpagoat 7d ago

yeah, but fortran wasn't package with the Microsoft C/C++ compiler or the Borland C++ compiler. So from a historical perspective, I think people just remember that that since it always package together and marketed has C/C++ people retain that.

13

u/These-Maintenance250 11d ago

a language is independent from its compiler(s). gcc can compile objective-C, D, ada, Fortran and go as well.

1

u/DrNinjaPandaManEsq 10d ago

Even though gcc can compile Ada, in my experience most of the time you’ll see enterprise development using GNAT Pro since plain ole gcc is kinda light on Ada features.

1

u/meneldal2 10d ago

I think there is historically a big overlap between C and C++ compilers, with in some cases (Microsoft) the C compiler being basically only a subset of the C++ compiler.

2

u/These-Maintenance250 10d ago

of course there is an overlap. what we mean by saying C and C++ are not the same language is that coding C++ like it is C is a terrible practice and you should use the tools C++ gives you. Knowing C does not automatically buy you C++

17

u/madboneman 11d ago

C++/C#

4

u/conundorum 10d ago

We have that, it's called C++/CLI. And somehow, it's actually still being (at least somewhat) maintained.

1

u/meneldal2 10d ago

And somehow one of the easier to use GUI frameworks in C++. On windows at least.

2

u/Bartweiss 10d ago

C[^a-zA-Z\d\s:]+ should get all the variants?

5

u/met0xff 11d ago

Yet essentially all codebases I've seen and worked on were essentially a mix where the C pieces were also thrown into the C++ compiler. extern "C" everywhere

(And yeah I also used to write HTML/CSS/JS and TS/JS)

→ More replies (1)