什么没有的sizeof()呢? [英] What does sizeof without () do?

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

问题描述

这个问题只是取笑了我,当我问他笔者什么
的sizeof * Q 做...
他告诉我这是一个非常基本的C的问题,我要看看。
但正如我看了看周围的SO并没有看到有人提问前,我将通过我自己现在就这样做:

The author of this question just made fun on me when I asked him what sizeof * q does... He told me that's a really basic C question and I should check it out. But as I looked around on SO and haven't seen some one asking before, I'll do it now by my self:

当它不带括号使用和/或输入C呢?

What does sizeof in C do when it is used without parentheses and/or type?

推荐答案

所以,如果我们看一下在的的sizeof ://标准 www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf\">C99草案节 6.5.3 一元运算符的段落的 1 的是如下:

So if we look at the grammar for sizeof in the C99 draft standard section 6.5.3 Unary operators paragraph 1 it is as follows:

sizeof unary-expression
sizeof ( type-name )

有是你离不开parenthesizes和部分 6.5.3.4 sizeof操作符类型名称的区别EM>段的 2 的说(的重点煤矿的):

There is a difference you can not use a type-name without parenthesizes and section 6.5.3.4 The sizeof operator paragraph 2 says(emphasis mine):

sizeof操作符得到其操作数的大小(以字节为单位),这可能是一个
  前pression 或类型的括号名称即可。[...]

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

为了完整起见,你可能不知道,如果我们可以用的sizeof 和前pression如果我们有parenthesizes,答案是肯定的,因为一个的 unary-前pression 的本身也包含parenthesizes。看到这种最简单的方法是将 A.2.1 防爆pressions 的从标准草案看部分,并通过像这样的语法工作

For completeness sake you may wonder if we can use sizeof with an expression if we have parenthesizes and the answer is yes since a unary-expression can itself contain parenthesizes. The easiest way to see this would be to look section A.2.1 Expressions from the draft standard and work through the grammar like so:

unary-expression -> postfix-expression -> primary-expression -> ( expression )

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

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