danmar/cppcheck — comment on commit 93e3e7361ee8048a8c06198908dfd98ef1a3d5a7
File:  line 0
By reif:

On ubuntu with gcc and g++ an extension of .c can be either C or C++ but an extension of .C can only be C++.

cppcheck$ cat both.c
#ifdef __cplusplus
#include
#else
#include
#endif

int main(int argc, char * argv[])
{
#ifdef __cplusplus
std::cout << "C++" << std::endl;
#else
printf("C\n");
#endif

return 0;
}
cppcheck$ gcc both.c
cppcheck$ ./a.out
C
cppcheck$ g++ both.c
cppcheck$ ./a.out
C++
cppcheck$ mv both.c both.C
cppcheck$ gcc both.C
/tmp/ccZe7vuW.o: In function `main':
both.C:(.text+0x14): undefined reference to `std::cout'
both.C:(.text+0x19): undefined reference to `std::basic_ostream >& std::operator<< >(std::basic_ostream >&, char const*)'
both.C:(.text+0x21): undefined reference to `std::basic_ostream >& std::endl >(std::basic_ostream >&)'
both.C:(.text+0x29): undefined reference to `std::basic_ostream >::operator<<(std::basic_ostream >& (*)(std::basic_ostream >&))'
/tmp/ccZe7vuW.o: In function `__static_initialization_and_destruction_0(int, int)':
both.C:(.text+0x51): undefined reference to `std::ios_base::Init::Init()'
both.C:(.text+0x56): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccZe7vuW.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
cppcheck$ g++ both.C
cppcheck$ ./a.out
C++