I donno where this belongs.
So do C++ compilers generate the same code as C compilers when it comes to C code?
I donno where this belongs.
So do C++ compilers generate the same code as C compilers when it comes to C code?
Two different C compilers probably don't generate the same code from the same C program in the first place. Anyway, you can compile to assembly output and compare for yourself.
EDIT:
If you're asking because you're thinking of mixing C and C++ code in the same program, then you should be aware that C++ compilers typically do stuff like name mangling, so if you want C code to be treated as C, you need to use extern "C" appropriately.
Last edited by laserlight; 02-16-2019 at 06:41 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I asked because: Would it make sense to write C code (take it to the next level and say production level C code if you want) in a C++ compiler?
There are two schools of thought:
- Yes, because C++ compilers will do things like stricter type checking.
- No, "I never saw a project for which C was better than C++ for any reason but the lack of a good C++ compiler." (Stroustrup)
Okay, related to the latter, but more positive for C, there is another argument: C and C++ are different programming languages.
Last edited by laserlight; 02-16-2019 at 06:55 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)