Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clarification on integer constant expressions

Tags:

c

c99

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.

Now, from standard which says:

(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);
like image 728
user963241 Avatar asked Feb 17 '26 08:02

user963241


1 Answers

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

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

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

like image 159
ouah Avatar answered Feb 19 '26 21:02

ouah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!