的#ifdef为32位平台 [英] #ifdef for 32-bit platform

查看:550
本文介绍了的#ifdef为32位平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我维护一个应用程序,我们已经遇到了一个问题,影响了STDLIB文件描述符限制。此问题只影响32位版本的标准库中。

In an application I maintain, we've encountered a problem with file descriptor limitations affecting the stdlib. This problem only affects the 32-bit version of the standard lib.

我设计了一个修复我的code和想实现它,但只编译32位可执行文件时。我支持#ifdef是什么pre处理器的符号,以确定code是否被编译为32位或64位的目标?

I have devised a fix for my code and would like to implement it, but only when compiling for 32-bit executable. What pre-processor symbol can I #ifdef for to determine whether the code is being compiled for a 32 or 64-bit target?

修改

对不起,没有提到,在code是跨平台,Linux和Windows,Solaris和其他一些Unix系统,主要是使用GCC编译。任何事实上的标准,我可以使用跨平台?

Sorry, didn't mention, the code is cross-platform, linux, windows, solaris and a few other unix flavors, mostly using GCC for compilation. Any de-facto standards I can use cross-platform?

编辑2

我已经发现了一些定义__ILP23和__LP64,似乎像他们可能工作......一个讨论的此处说明在UNIX平台上的背景。没有人有使用这些定义的经验吗?难道这将是有用的?

I've found some definitions "__ILP23" and "__LP64" that seem like they may work... a discussion here explains the background on the unix platform. Anyone had any experience with using these defines? Is this going to be usable?

推荐答案

我不知道如果有一个通用的高清#如果是适当的。 C ++标准几乎可以肯定没有定义。当然,还有平台spcefic的人虽然。

I'm not sure if there is a universal #if def that is appropriate. The C++ standard almost certainly does not define one. There are certainly platform spcefic ones though.

例如,Windows

For example, Windows

#if _WIN64 
// 64 bit build
#else
// 32 bit build
#endif

修改 OP提到这是使用Windows和非Windows之间的交叉编译GCC和其他编译器

EDIT OP mentioned this is a cross compile between Windows and Non-Windows using GCC and other compilers

有可用于所有平台和编译器没有通用的宏。的preprocessor魔一点点,虽然可以做的伎俩。假设你只工作在x86和AMD64芯片下面应该做的伎俩。它可以很容易地适用于其他平台,虽然

There is no universal macro that can be used for all platforms and compilers. A little bit of preprocessor magic though can do the trick. Assuming you're only working on x86 and amd64 chips the following should do the trick. It can easily be expanded for other platforms though

#if _WIN64 || __amd64__
#define PORTABLE_64_BIT
#else
#define PORTABLE_32_BIT
#endif

这篇关于的#ifdef为32位平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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