Huh, I never realized that C++ standards were removing C features. Time to be more careful about using g++ for everything.
#include <stdlib.h>
int main()
{
int *foo = malloc(sizeof(int));
return 0;
}
That works in C, but not in C++.There's actually another subtle different in there that main() means "unspecified arguments" in C, and "no arguments" in C++. ("No arguments" in C would be main(void).) However, it's no longer commonly used that way in C, but casts from void * to other types is very common in C.
The modern C++ way to do this ~safely isn't legal C, and yet the type pun isn't safe in C++. I believe using memcpy() to launder the bits is legal in both languages and in some cases your compiler can figure out what you're doing and not actually emit the unnecessary copy.
You have to explicitly pass -std=c17 (or whatever) to get standard-conforming behavior including trigraphs.