Re: [C or C++] Is this legal? sizeof *p

From: Jason (spacenjasset_at_yahoo.co.uk)
Date: 01/04/04


Date: Sun, 4 Jan 2004 12:22:30 -0000


"Jack Klein" <jackklein@spamcop.net> wrote in message
news:2csevvcntm2up8b4vm4e6khlnlbh366tp2@4ax.com...
...
> On Sat, 03 Jan 2004 17:17:30 -0500, Jeff Schwab <jeffplus@comcast.net>
> In C++, and in C except for one special case in C99, the sizeof
> operator is guaranteed not to evaluate its operand, merely use the
> operand to identify the type and hence the size.
...

Thanks, I suspected that be the case. I suppose that this sort of usage is
to be discouraged as a matter of readability. Although it does have the
advantage that if the type changes the sizeof *p need not.



Relevant Pages

  • Re: Null terminated strings: bad or good?
    ... The sizeof operator yields the size of its operand, ... If the type of the operand is a variable length array type, ... As far as I can tell, the standard doesn't explicitly forbid naming types larger than SIZE_MAX bytes, or even applying sizeof to such types -- it just describes the semantics of sizeof in a way that is logically impossible for such types. ... What this means, in effect, is that it's actually the size of its operand that is implementation-defined; the fact that the value is implementation-defined does not give the implementation the option of having sizeof yield any value other than "the size of it's operand". ...
    (comp.std.c)
  • Re: Regarding sizeof Operator
    ... "the operand of a sizeof operator is usually not evaluated" ... Although sizeof must evaluate the size of a variable length array under c99 ... "If the type of the operand is a variable length array type, ...
    (comp.lang.c)
  • Re: Null terminated strings: bad or good?
    ... The sizeof operator yields the size of its operand, ... As far as I can tell, the standard doesn't explicitly forbid naming types ... and yield any size_t value whatsoever. ...
    (comp.std.c)
  • Re: Null terminated strings: bad or good?
    ... I think I just found a paragraph in the standard that should solve this ... This should apply when the operand of sizeof is such that the result ... sizeof on an overly large value were undefined behavior, ...
    (comp.std.c)
  • Re: Sizeof question
    ... |> | sizeof returns the number of chars that array occupies. ... | On the most common system, a char is 1 byte though. ... operand, which may be an expression or the parenthesized ... operand is a variable length array type, ...
    (alt.comp.lang.learn.c-cpp)