平台无关的类型 [英] Platform independent types

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

问题描述

最近关于PIMPL和不透明指针的讨论让我想到了

我常见的关于在平台基础上定义

平台类型的构造。与结构类似,显然类型需要在头文件中完整以便于使用。


我的意思是类似以下内容。 ..

#ifdef PLATFORM1

typedef unsigned long unsigned64;

....

#elseif PLATFORM2

typedef unsigned long long unsigned64;

#endif


这样你可以确保给定类型的大小相同,

独立于平台。


所有的反对#if等等,有没有人有任何其他的

方法为了达到同样的效果?


谢谢

The recent discussion on PIMPL and opaque pointers made me think about
a construct I have seen commonly with respect to defining types on a
platform by platform basis. Unlike structs, obviously types needs to
be ''complete'' in header files for ease of use.

What I mean is something like the following...
#ifdef PLATFORM1
typedef unsigned long unsigned64;
....
#elseif PLATFORM2
typedef unsigned long long unsigned64;
#endif

That way you can ensure that a given type is the same size,
independent of platform.

With all the vitriol against "#if", etc, does anyone have any other
methods for achieving the same sort of effect?

Thanks

推荐答案

joseph cook写道:
joseph cook wrote:

最近关于PIMPL和不透明指针的讨论使我想到了

a构造我常见的关于定义
$ b的类型$ b平台平台基础。与结构类似,显然类型需要在头文件中完整以便于使用。


我的意思是类似以下内容。 ..

#ifdef PLATFORM1

typedef unsigned long unsigned64;

...

#elseif PLATFORM2

typedef unsigned long long unsigned64;

#endif


这样你可以确保给定类型的大小相同,

独立于平台。


所有的反对#if等等,任何人都有任何其他的

方法达到同样的效果?
The recent discussion on PIMPL and opaque pointers made me think about
a construct I have seen commonly with respect to defining types on a
platform by platform basis. Unlike structs, obviously types needs to
be ''complete'' in header files for ease of use.

What I mean is something like the following...
#ifdef PLATFORM1
typedef unsigned long unsigned64;
...
#elseif PLATFORM2
typedef unsigned long long unsigned64;
#endif

That way you can ensure that a given type is the same size,
independent of platform.

With all the vitriol against "#if", etc, does anyone have any other
methods for achieving the same sort of effect?



见标题< inttypes.h>


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

See header <inttypes.h>

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask



见标题< inttypes.h>
See header <inttypes.h>



但是那是's C99标题,不是C ++标题,对吧?

But that''s a C99 header, not a C++ Header, right?


joseph cook写道:
joseph cook wrote:

>请参阅标题< inttypes.h>
>See header <inttypes.h>



但这是一个C99标题,而不是C ++标题,对吗?


But that''s a C99 header, not a C++ Header, right?



大多数编译器已经提供它。它是C ++ 0x规范的一部分。


V

-

请删除大写''A在回复电子邮件的时候

我没有回复最热门的回复,请不要问

Most compilers already provide it. And it''s part of C++0x specification.

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


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

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