News:

Download Pelles C here: http://www.pellesc.se

Main Menu

How to determine compiler standard

Started by PhilG57, Yesterday at 06:45:07 PM

Previous topic - Next topic

PhilG57

Hi.  How can I, at compile time, determine and print the C standard the compiler is using.  I see __POCC__ to determine which version of Pelles IDE is being used, but not the C standard (11, 17, 22, etc.) with which my code is being compiled.  Thanks.

John Z

Hi Phil57,

Use the Menu: Project - Project Options, select Compiler in the tree view,  Now in that right side screen you will see 'C standard' and a drop down box.  The value in the box is the current C standard being used.

Use the 'C standard' drop down box to change to any other one you want.

'Project Options' is near the bottom of the Main Menu Project drop-down Menu btw.


John Z

Michele

If your scope is to use it in #if/#else#endif constructs to conditionally compile code based on the used standard you can use the symbols "__STDC_VERSION__  ", defined only when /Ze isn't used, or "__POCC_STDC_VERSION__" when /Ze is used.

From the help file:
Quote__STDC_VERSION__ Never defined when the /Ze option is used. The supported ISO C standard.
Defined as the integer constant 199901L when the /std=C99 option is used.
Defined as the integer constant 201112L when the /std=C11 option is used.
Defined as the integer constant 201710L when the /std=C17 option is used.
Defined as the integer constant 000000L (TBD) when the /std=C2X option is used. 

PhilG57

Hey, many thanks.  The following seems to work great:
#if __POCC_STDC_VERSION__ == 199901
#pragma message("diff.c: Compiler standard is C99.")
#else
#if __POCC_STDC_VERSION__ == 201112
#pragma message("diff.c: Compiler standard is C11.")
#else
#if __POCC_STDC_VERSION__  == 201710
#pragma message("diff.c: Compiler standard is C17.")
#else
#pragma message("diff.c: Compiler standard is unknown.")
#endif
#endif
#endif

Of course, now I'm wondering if there is any way to get this information at run time...
Thanks again.