的sizeof(x)的 [英] sizeof(x)

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

问题描述

在C99中提到:


" sizeof运算符产生其操作数的大小(以字节为单位),

可能是一个表达式或类型的带括号的名称。。

如果我没有错,这意味着


int x;

size_t y = sizeof(x);

无效。

且只有以下内容有效:

int x ;


size_t y = sizeof x;

然而我很困惑,并认为第一个也是有效的

C90 / C95(/ C ++ 03)。

In C99 it is mentioned:

"The sizeof operator yields the size (in bytes) of its operand, which
may be an expression or the parenthesized name of a type.".
If I am not wrong, this implies that

int x;

size_t y= sizeof(x);
is not valid.
and only the following is valid:
int x;

size_t y= sizeof x;
However I am puzzled, and thought the first was also valid in
C90/C95(/C++03).

推荐答案

On Sun,2008年3月30日22:50:00 +0300,Ioannis Vranos写道:
On Sun, 30 Mar 2008 22:50:00 +0300, Ioannis Vranos wrote:

在C99中提到:


" sizeof运算符产生其大小(以字节为单位)操作数,

可能是一个表达式或类型的带括号的名称。。


如果我没有错,这意味着


int x;


size_t y = sizeof(x);


无效。
In C99 it is mentioned:

"The sizeof operator yields the size (in bytes) of its operand, which
may be an expression or the parenthesized name of a type.".

If I am not wrong, this implies that

int x;

size_t y= sizeof(x);
is not valid.



你是; (x)是一个完全有效的表达式,所以没有问题

取大小为(x)。

You are; (x) is a perfectly valid expression, so there''s no problem
taking the size of (x).


Harald van Dijk写道:
Harald van Dijk wrote:

On Sun,2008年3月30日22:50:00 +0300,Ioannis Vranos写道:
On Sun, 30 Mar 2008 22:50:00 +0300, Ioannis Vranos wrote:

>在C99中提到:

" sizeof运算符产生其操作数的大小(以字节为单位),
可以是表达式或类型的带括号的名称。

如果我没错,这意味着

int x;

size_t y = sizeof(x);

无效。
>In C99 it is mentioned:

"The sizeof operator yields the size (in bytes) of its operand, which
may be an expression or the parenthesized name of a type.".

If I am not wrong, this implies that

int x;

size_t y= sizeof(x);
is not valid.



你是; (x)是一个完全有效的表达式,所以没有问题

取大小为(x)。


You are; (x) is a perfectly valid expression, so there''s no problem
taking the size of (x).



我第一次看到只有sizeof x在主页上的pdf有效 http://cprog.tomsweb.net 。


然后我检查了C99标准,它提到了上面显示的内容。

显然C99没有提到带括号的表达。


I first saw that only sizeof x is valid at the pdf hosted at
http://cprog.tomsweb.net.

Then I checked the C99 standard and it mentions what is shown above.
Clearly C99 doesn''t mention parenthesized expression.


Ioannis Vranos写道:
Ioannis Vranos wrote:

>

我第一次看到只有sizeof x在pdf托管的pdf上有效 http://cprog.tomsweb.net 。
>
I first saw that only sizeof x is valid at the pdf hosted at
http://cprog.tomsweb.net.



更具体地说,上面写道:


" sizeof以字节为单位返回操作数的大小;两种形式:

1)sizeof(类型)

2)sizeof表达式


More specifically the above writes:

"sizeof Returns size of operand in bytes; two forms:
1) sizeof(type)
2) sizeof expression"


然后我检查了C99标准,它提到了上面显示的内容。

显然C99没有提到带括号的表达式。
Then I checked the C99 standard and it mentions what is shown above.
Clearly C99 doesn''t mention parenthesized expression.


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

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