| 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.
|