NOTICE: The Processors Wiki will End-of-Life in December of 2020. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

Refer to Compiler Version in Your Source

From Texas Instruments Wiki
Jump to: navigation, search

Sometimes you need to refer to the version of the compiler from your source code. You can use the compiler predefined preprocessor macro __TI_COMPILER_VERSION__. Here is an example.

<syntaxhighlight lang='c'>

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

</syntaxhighlight>

Note relatively old versions of TI compilers do not supply __TI_COMPILER_VERSION__. To see if your compiler supports it, preprocess the example with the option -ppc and examine the resulting .pp file. If __TI_COMPILER_VERSION__ is supported, it will look something like this.

C:\dir>cl6x -ppc ver_ex.c
C:\dir>type ver_ex.pp
// ver_ex.c
// Examples of how to use __TI_COMPILER_VERSION__, the preprocessor
// symbol predefined by all TI compilers
int val = 6001000;                   // as an int
char *cgt_version = "6001000";  // as a string