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] [参考译文] [常见问题解答]编译器:参考源代码中的编译器版本号

Guru**** 1133960 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/tools/code-composer-studio-group/ccs/f/code-composer-studio-forum/924591/faq-compiler-refer-to-compiler-version-number-in-your-source

工具/软件:TI C/C++编译器

在源代码中引用编译器当前版本的最佳方法是什么?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    考虑以下示例...

    // version_example.c
    
    //有关如何使用__TI_Compiler_version__(所有
    TI 编译器预定义的预处理器//符号
    
    )的示例 int as_int =__TI_Compiler_version__; //作为 int
    
    #define EVAL_TO_STR (arg)#arg
    #define MKSTR (arg) EVAL_TO_STR (arg)
    char * as_string = MKSTR (__TI_Compiler_version__); //作为字符串 

    预处理器符号__TI_Compiler_version__由所有 TI 编译器预定义。  此示例展示了如何将其用作整数和字符串。   

    为了更详细地展示所发生的情况、以下命令使用 TI ARM 编译器版本20.2.1.LTS 构建此示例。  选项--gen_preprocessor_listing 会创建同名的预处理器列表文件、但文件扩展名更改为.rl。   

    % armcl --gen_preprocessor_listing version_example.c 

    以下是 version_example.rl 中的一些关键行 ...

    nint as_int =__TI_Compiler_version__; //作为 int
    XINT as _int = 20002001;
    
    ...
    
    NCHAR * as_string = MKSTR (__TI_Compiler_version__); //作为字符串
    Xchar *作为_string ="20002001"; 

    RL 文件中的每一行都以标识该行的大写字母开头。  n 显示预处理前的正常源代码行。  X 显示了预处理后的扩展源代码行。

    有关更多详细信息、请在 您的 CPU 系列的编译器手册中搜索 标题 为生成原始列表文件的子章节。

    谢谢、此致、

    乔治