c - __extension__ 关键字可以在所有编译器之间移植吗?

标签 c keyword portability

__extension__ 关键字可以在所有编译器之间移植吗? 我在 gcc 手册中查看了它,但他们没有提到这个关键字是否可移植。如果有人知道,我将感谢您的帮助。

最佳答案

不。 C 标准未涵盖的任何内容都是不可移植的。这就是为什么如果我们想要(或必须)使用编译器特定的扩展编译指示或属性,我们需要编写如此糟糕的代码。

#if  defined ( __GNUC__ )
#ifndef __weak
#define __weak   __attribute__((weak))
#endif /* __weak */
#ifndef __packed
#define __packed __attribute__((__packed__))
#endif /* __packed */
#endif /* __GNUC__ */


/* In HS mode and when the DMA is used, all variables and data structures dealing
   with the DMA during the transaction process should be 4-bytes aligned */

#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
#ifndef __ALIGN_END
#define __ALIGN_END    __attribute__ ((aligned (4U)))
#endif /* __ALIGN_END */
#ifndef __ALIGN_BEGIN
#define __ALIGN_BEGIN
#endif /* __ALIGN_BEGIN */
#else
#ifndef __ALIGN_END
#define __ALIGN_END
#endif /* __ALIGN_END */
#ifndef __ALIGN_BEGIN
#if defined   (__CC_ARM)      /* ARM Compiler */
#define __ALIGN_BEGIN    __align(4U)
#elif defined (__ICCARM__)    /* IAR Compiler */
#define __ALIGN_BEGIN
#endif /* __CC_ARM */
#endif /* __ALIGN_BEGIN */
#endif /* __GNUC__ */

关于c - __extension__ 关键字可以在所有编译器之间移植吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58784384/

相关文章:

c++ - 在不同的 Visual Studio 平台上运行时间不同?

c - SIGINT 信号仅被捕获一次

c - 除以 2 时十进制转为二进制 C

c++ - C/C++ 中 assert(false) 的更好替代方案

java - 这是使用 java 关键字 "interface"的正确位置吗?

r - R 中使用 Twitter Streaming API 进行 Oauth(使用 RCurl)

c - 运行时分析

java - 在线程中使用同步

c++ - 在 C++ 中,将静态成员函数指针用于 C API 回调是否安全/可移植?

c++ - C/C++ 中的可移植无符号长整型