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.

[参考译文] LAUNCHXL-F28P55X:C2000 编译器库中_ASSERT 的定义/声明

Guru**** 2513185 points
Other Parts Discussed in Thread: TI-CGT

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

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1561549/launchxl-f28p55x-definition-declaration-of-_assert-in-c2000-compiler-library

器件型号:LAUNCHXL-F28P55X


工具/软件:

我设置了一个新的链接工具来与我的项目一起运行、我遇到了_assert (...) 的问题  函数/定义。 从 ccs2020\ccs\tools\compiler\ti-cgt_c2000_22.6.2.LTs\lib\assert.h 中 src、_assert (……) 进行呼叫。 然而,我找不到这是定义的地方或它被记录的地方,所以我的解释者自然提出了一个错误,它找不到它的声明。 其中 _assert (...)  原因是什么?


#if defined(NDEBUG)
#define assert(_ignore) ((void)0)
#elif defined(NASSERT)
#define assert(_expr)   _nassert(_expr)
#else
#if (defined(__clang__) && defined(__arm__)) || \
    (defined(_AEABI_PORTABILITY_LEVEL) && _AEABI_PORTABILITY_LEVEL != 0)
     extern void __aeabi_assert(const char *expr, const char *file, int line);
     #define assert(__e) ((__e) ? (void)0 : \
	         __aeabi_assert(#__e, __FILE__, __LINE__))
#else
     #define assert(_expr)   _assert((_expr) != 0,      \
                    "Assertion failed, (" _STR(_expr) "), file " __FILE__ \
                    ", line " _STR(__LINE__) "\n")
#endif /* _AEABI_PORTABILITY_LEVEL, __clang__ */
#endif /* NDEBUG, NASSERT */

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

    它是一个未记录的内在函数。

    请考虑此示例。   

    /* file.c */
    #include <assert.h>
    
    void example(int arg)
    {
        assert(arg > 0);
        /* processing with arg that presumes arg is positive */
    }

    编译...

    cl2000 --opt_level=2 --src_interlist file.c

    使用优化级别 2 可以使生成的汇编代码更易于理解。  (这并不总是正确的,但在这种情况下。)  选项 -- src_interlist 保留汇编文件、并添加注释。  检查结果 file.asm 。  这些是关键线...

            CMPB      AL,#0                 ; [CPU_ALU] |6| 
            B         $C$L1,GT              ; [CPU_ALU] |6| 
            ; branchcc occurs ; [] |6| 
    ;***  	-----------------------    return;
            MOVL      XAR4,#$C$FSL1         ; [CPU_ARAU] |6| 
            LCR       #__abort_msg          ; [CPU_ALU] |6| 
            ; call occurs [#__abort_msg] ; [] |6| 
    $C$L1:

    参数(在寄存器中 AL ) 与 0 进行比较。  如果小于或等于 0、则使用该函数 __abort_msg 初始化过程。  此函数在编译器 RTS 库中提供。

    谢谢。此致、

    -乔治

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

    谢谢 George。

    这就是解释的原因、谢谢。 坚持这种内在的东西让我的表弟很开心,所以这是正确的路线。