#define值的大小 [英] Size of #define values

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

问题描述

如果值定义为

#define M_40 40

大小与 short (2字节)相同或者作为 char (1字节)或 int (4字节)?

Is the size the same as a short (2 bytes) or is it as a char (1 byte) or int (4 bytes)?

大小取决于您是否为32位或64位?

Is the size dependent on whether you are 32-bit or 64-bit?

推荐答案

没有大小不是一个类型,而是一个纯文本替换成你的C ++代码。 #define 是一个预处理指令,它在你的代码甚至开始编译之前运行。

#define has no size as it's not a type but a plain text substitution into your C++ code. #define is a preprocessing directive and it runs before your code even begins to be compiled .

C ++代码在替换后的大小是什么大小是什么C ++表达式或代码,你有。例如,如果你后缀 L 102L 那么它看起来很长,否则没有后缀,只是一个int 。所以4个字节在x86和x64可能,但这是编译器依赖。

The size in C++ code after substitution is whatever the size is of what C++ expression or code you have there. For example if you suffix with L like 102L then it is seen a long, otherwise with no suffix, just an int. So 4 bytes on x86 and x64 probably, but this is compiler dependent.

也许C ++标准的整数文字部分会为您清除(C ++ 03标准的第2.13.1-2节):

Perhaps the C++ standard's Integer literal section will clear it up for you (Section 2.13.1-2 of the C++03 standard):


整数文字的类型取决于其形式,值和后缀的
。如果
是十进制的,没有后缀,它有
这些类型的第一个,其中
的值可以表示:int,long
int;如果值不能
表示为long int,那么
行为是未定义的。如果它是八进制的
或十六进制并且没有后缀,它
有这些类型的第一个,其中
它的值可以表示:int,
unsigned int,long int, unsigned long
int。如果它后面有u或U,它的
类型是
中的第一个类型,它的值可以表示为:
unsigned int,unsigned long int。如果
后缀有l或L,它的类型是
,这些类型中的
值可以表示为:long int,
unsigned long int。如果它是由ul,lu,uL,Lu,U1,lU,UL或LU,
的后缀
它的类型是unsigned long int

The type of an integer literal depends on its form, value, and suffix. If it is decimal and has no suffix, it has the first of these types in which its value can be represented: int, long int; if the value cannot be represented as a long int, the behavior is undefined. If it is octal or hexadecimal and has no suffix, it has the first of these types in which its value can be represented: int, unsigned int, long int, unsigned long int. If it is suffixed by u or U, its type is the first of these types in which its value can be represented: unsigned int, unsigned long int. If it is suffixed by l or L, its type is the first of these types in which its value can be represented: long int, unsigned long int. If it is suffixed by ul, lu, uL, Lu, Ul, lU, UL, or LU, its type is unsigned long int

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

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