[cfe-dev] sizeof(sizeof(...))

Oliver Hunt oliver at apple.com
Fri Dec 14 14:48:44 PST 2007

On 14/12/2007, at 2:41 PM, Ted Kremenek wrote:

> On Dec 14, 2007, at 2:36 PM, Oliver Hunt wrote:
>> On 14/12/2007, at 2:21 PM, Bill Wendling wrote:
>>> Well, the standard says to "integer" type, so probably not unsigned.
>>> But that's my understanding of it. Though I don't believe that  
>>> sizeof
>>> should be evaluating the expression...
>> Indeed, my understanding was that sizeof expr merely evaluated the  
>> type of the expression, not the expression itself.
> Not always with VLAs.  From the C99 standard (
> The sizeof operator yields the size (in bytes) of its operand,  
> which may be an
> expression or the parenthesized name of a type. The size is  
> determined from the type of
> the operand. The result is an integer. If the type of the operand  
> is a variable length array
> type, the operand is evaluated; otherwise, the operand is not  
> evaluated and the result is an
> integer constant.
Egad, so a = sizeof(char[(int)sqrt(x)]); would be valid?  that scares  
me :-O
is this valid:

char[n*m] foo(int n, int m) { ... }

I can't remember the rules for VLAs so i don't know if you can return  
a VLA :-/


More information about the cfe-dev mailing list