For Programmers: Free Programming Magazines  


Home > Archive > C > February 2006 > Re: comp.lang.c FAQ list · Question 7.19b









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: comp.lang.c FAQ list · Question 7.19b
Micah Cowan

2006-02-27, 6:57 pm

"Robin Haigh" <ecl6rsh@leeds.ac.uk> writes:

> "Micah Cowan" <micah@cowan.name> wrote in message
> news:87acccd0nh.fsf@mcowan.barracudanetworks.com...

<snip>
[color=darkred]
> is a
> set
>
> 1. if expression is 0, I don't know what it means to evaluate b[0]


Simple, it will return the first element of b[], which has the type
"array of /n/ ints". sizeof() will return /n/ as a size_t (which is
currently 17).

> 2. if expression is 4, I then find myself evaluating b[4], which doesn't
> exist


Or, indeed, if it is 3. This is exactly why you have to be careful
when you use sizeof on a VLA, and it is also why VLAs are different
from ordinary arrays in this regard.

> 3. evaluating the expression might cause undefined behaviour.


It would in your #2 above. #1 will be fine.

> This isn't
> normally an issue in a sizeof, because the type of the operand expression is
> determined regardless of its behaviour if it were to be evaluated


Right.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com