在编译时确定字节序的便携/标准方法

Pen*_*ang 7 c c++

请不要将此标记为重复.该建议后重复实际上是在说有关运行时决定.最重要的是,那里的答案都没有回答我的问题.

我需要uint16_t用C/C++中的两个字节读取一个.所以,我需要决定我的代码编译的平​​台的endian格式.我目前在GNU C扩展中使用宏.

// 'size' is 'uint16_t' and read from big-endian format. 
// So if the platform is little-endian, I need to flip the btyes.
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__    
     size = ( size << 8 ) | ( size >> 8 );
#endif
Run Code Online (Sandbox Code Playgroud)

性能在我的用例中至关重要,因此ntohshtons不适合我.我需要在预处理时间内进行这种endian检查.

题.是否有标准方法(语言标准)来进行预处理?