Reputation: 7038
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);
Upvotes: 3
Views: 3572
Reputation: 145829
(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.
Upvotes: 6