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.

[FAQ] Compiler: Refer to compiler version number in your source

Tool/software: TI C/C++ Compiler

What is the best way to refer to the current version of the compiler in your source code?

  • Consider this example ...

    // version_example.c
    // Examples of how to use __TI_COMPILER_VERSION__, the preprocessor
    // symbol predefined by all TI compilers
    int as_int = __TI_COMPILER_VERSION__;                   // as an int
    #define EVAL_TO_STR(arg) #arg
    #define MKSTR(arg) EVAL_TO_STR(arg)
    char *as_string = MKSTR(__TI_COMPILER_VERSION__);       // as a string

    The preprocessor symbol __TI_COMPILER_VERSION__ is predefined by all TI compilers.  This example shows how to use it as an integer, and as a string.  

    To show more detail on what happens, the following command builds this example with TI ARM compiler version 20.2.1.LTS.  The option --gen_preprocessor_listing creates a preprocessor listing file of the same name, but with file extension changed to .rl.  

    % armcl --gen_preprocessor_listing version_example.c

    Here are some key lines from version_example.rl ...

    Nint as_int = __TI_COMPILER_VERSION__;                   // as an int
    Xint as_int = 20002001;
    Nchar *as_string = MKSTR(__TI_COMPILER_VERSION__);       // as a string
    Xchar *as_string = "20002001";

    Every line in a .rl file starts with a capital letter which identifies that line.  N shows a normal line of source before preprocessing.  X shows an expanded line of source after preprocessing.

    For more details, please search the manual of the compiler for your CPU family for the sub-chapter titled Generating a Raw Listing File.

    Thanks and regards,