I compile this code under CentOs8 with the GNU compiler:
#include <stdlib.h>
int main() {
int *a = malloc(3 * sizeof(int));
return 0;
}
When I name it a.cpp, both of the compile commands failed:
g++ -o a a.cpp
gcc -o a a.cpp
But after I rename it to a.c, this compile command succeeds:
gcc -o a a.c
This is C code, NOT C++ code. I believe using gcc or g++ should make the difference, but it seems the compiler only considers the filename extension.
Could you please provide some details on this?