Or rather not to - because you will need to fix all malloc calls adding casting to them... And so on...
Printable View
Yes, that would be one consequence of using C++ to compile C code. Again, I'm not saying anyone should, or shouldn't use the C++ compiler to compile C, just regurgitating someone else's reasoning for doing so. It's really up to the individual (or technical leader if you work for a company, perhaps).
--
Mats
No, it won't compile without a few modifications, but it can compile. I never mentioned it will compile as-is.
Four big reasons:
No implicit function calls allowed.
No missing return types of functions or arguments allowed.
C++ compilers are often more conforming than C compilers. For example, assigning one type to a variable of another type is not allowed without an explicit cast, both in C and C++, yet most C compilers allow it with merely a warning.
More type-safe.
These are the only reasons needed to prefer compiling C code as C++ code. There are further advantages to C++, as well, and probably further advantages to compiling as C++ code, but this is more than enough.
In the end, it will work exactly like the code was compiled in a C compiler, so no harm comes from doing it.
And as far as casting malloc goes, that's really irrelevant. The only reason you shouldn't cast it is because it will hide an implicit call (or supress the warning). In C++, implicit function calls are not allowed, so you can't make that mistake.
This is my view on the whole, anyway.