Why do I see warnings about undefined pragmas in headers during compilation?

Note: Applies to RTI DDS 4.0. This problem was resolved in RTI DDS 4.1b.

Let's start with some general background information: 

#pragma statements provide a way to control some features of the compiler. Some examples of  #pragma statements implemented by different compilers include:

  • enabling or disabling specific compilation warnings 
  • setting the optimization level 
  • specifying alignment for members of C structures 
  • etc. 

Pragmas are compiler-specific: exactly what  #pragma statements are supported, and what they mean, is not defined by the C or C++ standard, but by your compiler's authors. Therefore a  #pragma statement understood by one compiler may not be understood by another. Some compilers (notably GCC) even support different  #pragma statements on different architectures. 

Suppose you have a program which uses  #pragma statements that was developed using compiler X. Then you switch to compiler Y, which doesn't understand the same #pragma statements. Depending on what those  #pragma statements do, this may cause no problems at all, or may cause the code not to compile or link, or it may cause (sometimes hard-to-find) problems at run-time. To protect against this, your compiler may warn you when it encounters #pragma directives it doesn't understand. 

This behavior may result in pragma-related compilation warnings in RTI DDS 4.0 headers when you enable all of your compiler's warnings (using e.g. gcc -Wall). 

The RTI DDS 4.0g header files include  #pragma statements to disable certain compilation warnings from Microsoft's Visual Studio C/C++ compilers. We locally disable those warnings for some blocks of code that would otherwise trigger potentially confusing/misleading warnings even though there is no problem with the code itself. 
These  #pragma statements aren't understood by non-Microsoft compilers. With GCC, you can use the -Wall -Wno-unknown-pragmas flags, which will disable pragma-related warnings from the compiler. 

The only situation in which you may not wish to disable unknown pragma warnings is if your own application code includes #pragma statements and you need to be able to debug problems with those. In that case, you can ignore the unknown pragma warnings from RTI DDS headers.

Programming Language: