2 ms·
How much of the UB in C is carried over to C++? Does the C++ standards committee carry a lot of the UB over into C++, or try to fix the issue? If C++ doesn't ha
by Paul-ish 8y ago
How much of the UB in C is carried over to C++? Does the C++ standards committee carry a lot of the UB over into C++, or try to fix the issue? If C++ doesn't have the same UB, maybe the solution is to compile C code with a C++ compiler.
- jcranmer 8y agoThe intent of C++ is that the subset that is valid C code ends up being largely semantically identical in C++ and C. There are some differences, particularly related to the type system (for example, in C, a ternary expression is an rvalue, where it can be an lvalue expression in C++). Most, perhaps all, of the undefined behavior is retained C++. There is potentially a case where C eliminated undefined behavior that C++ retained--the "union trick" for getting access to the bits of a float was made legal in C99 but the C++ language (modified to support unrestricted unions) suggests that it is undefined behavior in C++.