在OSX中定义“BYTE_ORDER”宏的位置?

时间:2012-06-17 22:31:27

标签: c macos unix endianness

我想在我的Xcode项目中使用“BYTE_ORDER”宏,但我不能,因为我不知道它定义在哪个头中。

1 个答案:

答案 0 :(得分:0)

当我查看我的Xcode 4.3.X安装时,我发现“byte_order.h”文件位于以下几个位置:

[/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform]:;!fi
find . -name byte_order.h -print
./Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/architecture/byte_order.h
./Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/machine/byte_order.h
./Developer/SDKs/MacOSX10.6.sdk/usr/include/architecture/byte_order.h
./Developer/SDKs/MacOSX10.6.sdk/usr/include/architecture/i386/byte_order.h
./Developer/SDKs/MacOSX10.6.sdk/usr/include/architecture/ppc/byte_order.h
./Developer/SDKs/MacOSX10.6.sdk/usr/include/machine/byte_order.h
./Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/architecture/byte_order.h
./Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/machine/byte_order.h
./Developer/SDKs/MacOSX10.7.sdk/usr/include/architecture/byte_order.h
./Developer/SDKs/MacOSX10.7.sdk/usr/include/architecture/i386/byte_order.h
./Developer/SDKs/MacOSX10.7.sdk/usr/include/machine/byte_order.h

您可能希望在.c文件中执行“#include <architecture/byte_order.h>”以获取byte_order宏。

对于实际的“BYTE_ORDER”定义本身,这是在几个特定的​​地方定义的,但它的定义方式似乎是出于非常具体的目的。例如,这定义:

#define __DARWIN_BYTE_ORDER __DARWIN_LITTLE_ENDIAN
#define BYTE_ORDER  __DARWIN_BYTE_ORDER
./Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/i386/endian.h

仅适用于内核扩展(驱动程序)。

这定义:

#     define BYTE_ORDER LITTLE_ENDIAN
#     define BYTE_ORDER BIG_ENDIAN
#  endif /* BYTE_ORDER */
#  define X_BYTE_ORDER BYTE_ORDER
./Developer/SDKs/MacOSX10.7.sdk/usr/X11/include/X11/Xarch.h

适用于X11的东西(ewww)。

我想说最好的办法就是在“NXHostByteOrder”文件中使用“byte_order.h”内联函数,这样就可以得到当前主机的字节顺序。