linux vs osx,OSX vs Linux:如何处理unsigned long和uint64_t?

#include

#include

#include

int main()

{

static const char* b2s[] = { "no", "yes" };

printf("%s\n", b2s[std::is_same::value]);

}

回报yes在Linux编译的时候,和no当OSX编译。

我在阅读的同时试着理解为什么这是apparently normal。 如果我正在开发一个库并且希望它是可移植的,我该如何处理这个问题?我需要处理每个操作系统的偏好吗?

下面是一个例子:

foo.h中

#include

template

struct Foo

{

static const char id;

};

Foo.cpp中

#include "foo.h"

#define DEFINE_FOO(type_,id_) \

template <> const char Foo::id = id_; \

template <> const char Foo::id = id_;

DEFINE_FOO( bool,'a')

DEFINE_FOO( int8_t,'b')

DEFINE_FOO(uint8_t,'c')

DEFINE_FOO(int16_t,'d')

DEFINE_FOO(uint16_t,'e')

DEFINE_FOO(int32_t,'f')

DEFINE_FOO(uint32_t,'g')

DEFINE_FOO(int64_t,'h')

DEFINE_FOO(uint64_t,'i')

DEFINE_FOO( float,'j')

DEFINE_FOO( double,'k')

// OSX requires this, but Linux considers it a re-definition

// DEFINE_FOO(unsigned long,'l')

由于我的图书馆的一部分,以前被编译并链接当我需要创建一个可执行文件时(比如main.cpp)。通常情况下,这看起来像:

$(CC) -c -Wall -std=c++0x -o foo.o foo.cpp

$(CC) -Wall -std=c++0x -o main main.cpp foo.o

这将工作在一个平台上,但在另一个失败;如果我在foo.cpp中取消注释DEFINE_FOO(unsigned long,'l'),那么OSX很高兴,但是Linux说Foo正在被重新定义。反之亦然。

这怎么可能是正常的?有没有一种“便携式”的方式来解决这个问题?

2016-04-23

Sheljohn

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值