compiler complies everything as C++

noticed as i downloaded some code from here to use in keil that i got some linker errors. some digging about made me notice it had a mixture of .cpp and .c files and include files shared between the two.

save this file as test.c and compile it in the online compiler.

#ifdef __cplusplus
#error being compiled as C++ !
#endif

#include <stdio.h>

void test(void) {
    printf("hello");
}

throws an error that its being compiled as C++ rather than plain C. keil works fine.

one consequence is that if you mix c++ and c in the online complier everything make work, but in the real world you may have to use external linkage (aka extern "C" {...}) to link things up correctly.


Please log in to post comments.