如何在编译时检查标志是否存在?
我使用 -LITTLE
标志来选择 little endian 计算和-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
就像
gcc -LITTLE my_c_file.c
我想检查用户在编译时是否没有给出任何标志,然后编译不会发生并给出错误。
我怎样才能做到这一点?
I am using the -LITTLE
flag for choosing little endian calculation and-BIG
for big endian calculation in my project while compiling.
#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
like
gcc -LITTLE my_c_file.c
I want to check if user hasn't given any of flag at compile time then compilation does not takes place and give an error.
How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你的意思是
gcc -DLITTLE
。您可以使用类似的内容:
猜测一下,您可能还想要:
当然,如果您可以编写不关心正在运行的机器的字节序并避免整个混乱的代码,那就更好了。
I think you mean
gcc -DLITTLE
.You can use something like:
At a guess, you might also want:
Of course, it's better if you can write code that doesn't care about the endianness of the maching that you are running on and avoid the whole mess.
尝试
Try
您可以自动检测平台的字节性别。请参阅 boost/detail/endian.hpp。
You can detect the byte sex of the platform automatically. See boost/detail/endian.hpp.