如何在gcc编译时识别x86与x86_64? [英] How do I identify x86 vs. x86_64 at compile time in gcc?

查看:1085
本文介绍了如何在gcc编译时识别x86与x86_64?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在x86和x86_64 linux上编译部分代码,而不是s390 linux或其他版本.如何使用C中的宏定义来实现它?我知道 linux 用于确定linux操作系统,并且 386 486 586 用于确定CPU体系结构.是否有一个简单的宏定义来确定x86 linux和x86_64 linux?谢谢

I want to compile part of my code only on x86 and x86_64 linux, but not s390 linux or others. How to use the macro define in C to achieve it? I know linux is to determine linux OS, and 386, 486 and 586 to determine CPU architecture. Is there an easy macro define to determine x86 linux and x86_64 linux? Thanks

推荐答案

您可以轻松地检测是否处于64位模式:

You can detect whether or not you are in a 64 bit mode easily:

#if defined(__x86_64__)
/* 64 bit detected */
#endif
#if defined(__i386__)
/* 32 bit x86 detected */
#endif

这篇关于如何在gcc编译时识别x86与x86_64?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆