我使用的-LITTLE 标志选择小端计算
-BIG为大端在我的项目计算而编制.
#ifdef LITTLE
{
// i'm using i for operating one loop
}
#endif
/* If the system is big-endian, store bytes in array as forward order */
#ifdef BIG
{
// using i for loop
}
#endif
Run Code Online (Sandbox Code Playgroud)
喜欢
gcc -LITTLE my_c_file.c
Run Code Online (Sandbox Code Playgroud)
我想检查用户是否在编译时没有给出任何标志,然后编译不会发生并给出错误.
我怎样才能做到这一点?
我想你的意思是gcc -DLITTLE.
您可以使用以下内容:
#if !defined(LITTLE) && !defined(BIG)
#error either LITTLE or BIG must be defined
#endif
Run Code Online (Sandbox Code Playgroud)
猜测,您可能还需要:
#if defined(LITTLE) && defined(BIG)
#error only one of LITTLE or BIG must be defined
#endif
Run Code Online (Sandbox Code Playgroud)
当然,如果你能编写的代码不关心你正在运行的机器的字节顺序并避免整个混乱,那就更好了.