This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/ARM-CGT: --preproc_only creates weired style pragma

Part Number: ARM-CGT
Other Parts Discussed in Thread: HALCOGEN

Tool/software: TI C/C++ Compiler

Compiling with --preproc_only creates some weired style C-Code when e.g., float.h is included (I only cecked system headers float, math etc, and not HALCoGen generated).

Example Code:

#include <float.h>
int main(void) {
	return 0;
}

And -pp gives (newlines removed), and these are the first lines of code:

# pragma diag_push
# pragma CHECK_MISRA("-19.7")
# pragma CHECK_MISRA("-19.4")
# pragma CHECK_MISRA("-19.1")
# pragma CHECK_MISRA("-19.15")
# pragma diag_pop

_Pragma("diag_push")
_Pragma("CHECK_MISRA(\"-19.4\")")
_Pragma("CHECK_MISRA(\"-19.1\")")
_Pragma("CHECK_MISRA(\"-19.6\")")

#pragma diag_push
#pragma CHECK_MISRA("-19.4")

....

It's always the same for the system headers:

  •  Frist the misra rules 19.7, 19.4, 19.1 and 19.15 have these weired pragma which exactly one whitespace between # and pragma
  • after that all #pragams are fine (no whitespace between # and pragma)

Now my questions are:

  • What is this? I am not aware that this is valid C-code.
  • Why are only these four pragmas that weired, and all other are normal?

CCS-Project: pp-pragma.zip

  • The lines you point out originate in the header file_ti_config.h, which is included by float.h.

    /*Unsupported pragmas are omitted */
    #ifdef __TI_COMPILER_VERSION__
    # pragma diag_push
    # pragma CHECK_MISRA("-19.7")
    # pragma CHECK_MISRA("-19.4")
    # pragma CHECK_MISRA("-19.1")
    # pragma CHECK_MISRA("-19.15")
    # define _TI_PROPRIETARY_PRAGMA(arg) _Pragma(arg)
    # pragma diag_pop
    #else
    # define _TI_PROPRIETARY_PRAGMA(arg)
    #endif
    
    _TI_PROPRIETARY_PRAGMA("diag_push")
    _TI_PROPRIETARY_PRAGMA("CHECK_MISRA(\"-19.4\")")
    _TI_PROPRIETARY_PRAGMA("CHECK_MISRA(\"-19.1\")")
    _TI_PROPRIETARY_PRAGMA("CHECK_MISRA(\"-19.6\")")
    

    user6135372 said:
    What is this? I am not aware that this is valid C-code.

    It is valid to have space between the # and the name of the preprocessor directive.

    user6135372 said:
    Why are only these four pragmas that weired, and all other are normal?

    That is the result of preprocessing an invocation of the macro _TI_PROPRIETARY_PRAGMA.

    Thanks and regards,

    -George

  • Thanks.

    Just one minor thing: Could you elaborate why this space/no space thing is not consistent within the system headers? Is there a reason or is it just as it is and that's it.

  • There is no reason.  When working on the header files, we focus on correctness and maintainability.  Small inconsistencies in the spacing are not a concern.

    Thanks and regards,

    -George