Topic: constant-expressions (was: Static Const Members...)


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Tue, 1 Mar 1994 02:15:52 GMT
Raw View
rfg@netcom.com (Ronald F. Guilmette) writes:

>OK.  Would anyone care to speculate on that validity of the following
>(somewhat different) code?
>
> const struct A { int x; } object = { 3 };
>
> int array[object.x];

It's not valid.  See ARM 5.19:

 "A constant-expression can involve only literals, enumerators,
 const values of integral types initialized with constant expressions,
 and sizeof expresions."

The expression `object.x' involves the sub-expression `object', and
`object' is not a "const value of integral type".

In case there should be any lingering doubt, ARM 5.19 states quite
explicitly that "class objects ... cannot be used".

--
Fergus Henderson - fjh@munta.cs.mu.oz.au