Home > Blockchain >  Where to find C #pragma syntax parameters
Where to find C #pragma syntax parameters

Time:12-14

Where to find C #pragma syntax parameters. i can't find a specific description in compiler doc,and also in c99 manual

find #pragma helper for specify paltform, such as for aarch64 platform, C language, cross-compiler: aarch64-linux-gnu-gcc

CodePudding user response:

The whole purpose of #pragma is to provide a directive which compilers should ignore if they don't recognize it and thereby allow a means to port code using non-standard language features between compilers.


The C standard C17 6.10.6 only standardizes 3 pragmas:

#pragma STDC FP_CONTRACT on-off-switch
#pragma STDC FENV_ACCESS on-off-switch
#pragma STDC CX_LIMITED_RANGE on-off-switch

All other pragmas are compiler-specific, by their very nature.


Where to find C #pragma syntax parameters

In 6.10.6 of any standard between C99 and C17:

# pragma pp-tokensopt new-line

Meaning that a pragma may be followed by a number of pre-processor tokens, which in turn means that almost anything goes.

There is also the _Pragma operator (6.10.9) using the syntax:

_Pragma ( string-literal )

This behaves the same as #pragma but you provide a string instead of preprocessor tokens. This allows one to use _Pragma inside function-like macros.


As for finding out which pragmas that are supported for a particular compiler for a particular system, that's another story. For example gcc specific ones, both for all gcc compilers as well as for various target ports: https://gcc.gnu.org/onlinedocs/gcc/Pragmas.html#Pragmas

  • Related