Error extern "C" # 2040: ID expected

I'm still trying to compile a C console application, the compilation procedure is still not with the error below:

"Main.c", line 51: error #2040: expected an identifier extern "C" void TreatReceivedSignal( int NoSignal ) ; ^ 1 error detected in the compilation of "Main.c". gmake: *** [Main.o] Error 2 

below is the extern method declaration in C code:

 extern "C" void TreatReceivedSignal( int NoSignal ) ; 

I am using the HP-UX aCC compiler [HP C / aC ++ B3910B A.06.26], I also enabled the -Ae compilation flag to enable C99 support. It seems that the compiler cannot recognize "extern" C "" as a reserved word C, some other compilation flag may be set. Any idea, please, can solve this problem? Thanks a lot in advance. Relations

+6
source share
1 answer

The extern "C" construct is specific to C ++, it cannot be used in C. And the compiler treats your source file as a C source file, since it has a .c extension.

The most common task is to use a preprocessor to conditionally add this for C ++ compilations:

 #ifdef __cplusplus extern "C" { #endif /* Standard C prototypes */ #ifdef __cplusplus } #endif 
+12
source

Source: https://habr.com/ru/post/943537/


All Articles