澄清整数常量表达式 [英] Clarification on integer constant expressions

查看:106
本文介绍了澄清整数常量表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些地方我已经读到整数常量表达式包含整数常量,例如:

Somewhere I've read that integer constant expressions consists integer constants such as:

(5 + 5) //integer constant expression

这是我见过的唯一例子。

That was the only example I have seen.

现在,从标准中说:


(C99 6.6 / 6)整数常量表达式应具有整数类型
和只能包含整数常量,枚举
常量,字符常量,sizeof表达式(其结果为
整数常量)以及浮点常量(它们是强制转换的立即数bbb操作数)的操作数。整数常量表达式
中的类型转换运算符只能将算术类型转换为整数类型,除非将操作数
的一部分转换为sizeof运算符。

(C99 6.6/6) An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants, and floating constants that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert arithmetic types to integer types, except as part of an operand to the sizeof operator.

那么,如果我对,这些整数表达式是否全部在下面?

So, are all these integer expressions below if I'm right?

int i; float f = 3.14f;

i = 42;
i = f;
i = (int)(5/3.14f);


推荐答案

(int)(5 /3.14f)不是整数常量表达式。

(int)(5/3.14f) is not an integer constant expression.

您使用的浮点常量不是强制转换的直接操作数

You are using a floating constant that is not an immediate operands of cast.

当然在 i = f; 对象 f 不是整数常量表达式。

And of course in i = f; the object f is not an integer constant expression.

这篇关于澄清整数常量表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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