Pragma Error Syntax
Contents |
Three forms of this directive (commonly known as pragmas) are specified by the 1999 C standard. A C compiler is free to attach any meaning it likes to other pragmas. GCC
Pragma In C
has historically preferred to use extensions to the syntax of the language, such #pragma message as __attribute__, for this purpose. However, GCC does define a few pragmas of its own. These mostly have effects pragma pack in c on the entire translation unit or source file. In GCC version 3, all GNU-defined, supported pragmas have been given a GCC prefix. This is in line with the STDC prefix on
Pragma C++
all pragmas defined by C99. For backward compatibility, pragmas which were recognized by previous versions are still recognized without the GCC prefix, but that usage is deprecated. Some older pragmas are deprecated in their entirety. They are not recognized with the GCC prefix. See Obsolete Features. C99 introduces the _Pragma operator. This feature addresses a major problem with ‘#pragma’: being a
Pragma Meaning
directive, it cannot be produced as the result of macro expansion. _Pragma is an operator, much like sizeof or defined, and can be embedded in a macro. Its syntax is _Pragma(string-literal), where string-literal can be either a normal or wide-character string literal. It is destringized, by replacing all ‘\\’ with a single ‘\’ and all ‘\"’ with a ‘"’. The result is then processed as if it had appeared as the right hand side of a ‘#pragma’ directive. For example, _Pragma ("GCC dependency \"parse.y\"") has the same effect as #pragma GCC dependency "parse.y". The same effect could be achieved using macros, for example #define DO_PRAGMA(x) _Pragma (#x) DO_PRAGMA (GCC dependency "parse.y") The standard is unclear on where a _Pragma operator can appear. The preprocessor does not accept it within a preprocessing conditional directive like ‘#if’. To be safe, you are probably best keeping it out of directives other than ‘#define’, and putting it on a line of its own. This manual documents the pragmas which are meaningful to the preprocessor itself. Other pragmas are meaningful to the C or C++ compilers. They are documente
Control Error and Warning Messages Formatting of Diagnostics Individual Warning Groups Options to Control Clang Crash gcc pragma Diagnostics Options to Emit Optimization Reports Current limitations Other Options
Pragma Omp
Language and Target-Independent Features Controlling Errors and Warnings Controlling How Clang Displays Diagnostics Diagnostic pragma in c structure padding Mappings Diagnostic Categories Controlling Diagnostics via Command Line Flags Controlling Diagnostics via Pragmas Controlling Diagnostics in System Headers Enabling All Diagnostics Controlling Static https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html Analyzer Diagnostics Precompiled Headers Generating a PCH File Using a PCH File Relocatable PCH Files Controlling Code Generation Profile Guided Optimization Differences Between Sampling and Instrumentation Using Sampling Profilers Sample Profile Formats Sample Profile Text Format Profiling with Instrumentation Disabling Instrumentation Controlling Debug Information Controlling Size http://clang.llvm.org/docs/UsersManual.html of Debug Information Controlling Debugger "Tuning" Comment Parsing Options C Language Features Extensions supported by clang Differences between various standard modes GCC extensions not implemented yet Intentionally unsupported GCC extensions Microsoft extensions C++ Language Features Controlling implementation limits Objective-C Language Features Objective-C++ Language Features OpenMP Features Controlling implementation limits Target-Specific Features and Limitations CPU Architectures Features and Limitations X86 ARM PowerPC Other platforms Operating System Features and Limitations Darwin (Mac OS X) Windows Cygwin MinGW32 MinGW-w64 clang-cl Command-Line Options The /fallback Option Introduction¶ The Clang Compiler is an open-source compiler for the C family of programming languages, aiming to be the best in class implementation of these languages. Clang builds on the LLVM optimizer and code generator, allowing it to provide high-quality optimization and code generation support for many targets. For more general information, please see the
preprocessor. The preprocessor examines the code before actual compilation of code begins and resolves all these directives before any code is actually generated by regular statements. These preprocessor directives extend only across http://www.cplusplus.com/doc/tutorial/preprocessor/ a single line of code. As soon as a newline character is found, the preprocessor directive is ends. No semicolon (;) is expected at the end of a preprocessor directive. The only way a preprocessor directive can extend through more than one line is by preceding the newline character at the end of the line by a backslash (\). macro definitions (#define, #undef) To in c define preprocessor macros we can use #define. Its syntax is: #define identifier replacement
When the preprocessor encounters this directive, it replaces any occurrence of identifier in the rest of the code by replacement. This replacement can be an expression, a statement, a block or simply anything. The preprocessor does not understand C++ proper, it simply replaces any occurrence of identifier by replacement. 1
2
3
#define TABLE_SIZE pragma in c 100 int table1[TABLE_SIZE]; int table2[TABLE_SIZE]; After the preprocessor has replaced TABLE_SIZE, the code becomes equivalent to: 1
2
int table1[100]; int table2[100]; #define can work also with parameters to define function macros: #define getmax(a,b) a>b?a:b This would replace any occurrence of getmax followed by two arguments by the replacement expression, but also replacing each argument by its identifier, exactly as you would expect if it was a function: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
// function macro #include
2
3
4
5
#define TABLE_SIZE 100 int table1[TABLE_SIZE]; #undef TABLE_SIZE #define TABLE_SIZE 200 int table2[TABLE_SIZE]; This would generate the same code as: 1
2
int table1[100]; int table2[200]; Function macro definitions accept two special operators (# and ##) in the replacement sequence: The operator #, followed by a parameter name, is replaced by a string literal that contains the argument passed (as if enclosed between double quotes): 1
2
#define str(x) #x