Afficher un message
Vieux 19/10/2007, 00h59   #8
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: The sizeof operator : sizeof(++i)

Mark McIntyre <markmcintyre@spamcop.net> writes:
[...]
> I believe that sizeof() doesn't evaluate its operand (unless its a
> VLA, I think), so the increment is never executed.


Correct.

For the record, here's what the standard says (C99 6.5.3.4p2):

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.

There are some odd cases that this doesn't cover, where either the
standard says the operand isn't evaluated enen though it really needs
to be, or the operand is evaluated whne it really doesn't need to be.
All such cases involve indirect uses of VLAs (variable length arrays).
We discussed this recently in comp.std.c, subject "Evaluating the
operand of sizeof".

But if you're not using VLAs, none of this is relevant; the operand of
sizeof won't be evaluated if no VLAs are involved.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
 
Page generated in 0,07025 seconds with 9 queries