Home > Back-end >  C and C see which compiler used for which code
C and C see which compiler used for which code

Time:06-05

Im currently working on a big project that uses C and c code in one project using the extern "c" keyword in my declartions.

However I am unsure whether the compiler is actually doing anything with this as my output is the same when using the C keyword.

Is there a way to print something to the console to show what compiler was used for a specific peice of code in my project or a way to see if something is actually being compiled in C or c .

For example I tried using std::cout << something in the c code and it almost worked, the error didnt say anything like std not found or cout not found IIRC which I found to be a bit strange.

Ive tried googling this and didnt find any results. Thanks for any help!

Edit. Im using G as my compiler and would like the code to work on other compilers. my c code should work on both c and c but I need it to be C as im using union type pruning. Im at work right now so I cant recall the error message exactly. I also get the same ouput changing file extention to .c. Is there a way to see if the code is being compiled as C or c thanks!

CodePudding user response:

to answer your specific question about knowing if its a c or c compiler processing your code you can look for

__cplusplus

standard define

if common to see

 #ifdef __cplusplus
    extern "C"{
 .....

CodePudding user response:

It depends on the extention of your files for g . If your file is .cpp g is used. If your file is .c then gcc is used.

Concerning extern "C" -- this is a cpp construct to inform the compiler that C abi should be used and none c name mangling applied. You can read on the mangling. As this construct has meaning for c , i would expect it to be in a .cpp file.

  •  Tags:  
  • c c
  • Related