sizeof() style question

  • Thread starter Christopher C. Stacy
  • Start date
T

Tim Rentsch

Lawrence Kirby said:
However this was in the context of an operator invocation/function call. :)

Right. As I said, my comments were intended primarily as humor.
The posting really should have included a smiley - my sense of
humor is a little too dry at times. :)
 
D

Dave Thompson

On Thu, 09 Jun 2005 23:13:19 GMT, Martin Ambuhl
So either
sizeof(type)
or
sizeof expression
is correct, depending on the situation.
Some people, for reasons known only to them, insist on parenthesizing
the expression, but
sizeof(expression)
and
sizeof expression
mean exactly the same thing. Note that 'sizeof variable' is only a
special case of 'sizeof expression'.

As long as expression does not expose any operator(s) with precedence
below unary; if it does/would the parentheses are needed.

The operators that normally affect (produce) a result type we want to
take the size of like *ptr ptr->mem (str).mem ary[sub] are OK, and the
lower-precedence ones are rarely needed. But if we want, e.g. in a
macro, room for "at least 'long' but bigger if needed for the value"
sizeof ( (x) + 0L ) works but sizeof (x) + 0L doesn't.

- David.Thompson1 at worldnet.att.net
 
D

Dave Thompson

On Fri, 10 Jun 2005 21:30:56 +0000 (UTC), Malcolm

Except that it's a compile-time function. But I agree that in a
mathematical sense the result is a function of the (type of the)
parameter. I don't think that it's really an operator, it doesn't
operate on anything.

Nonsense. Mathematical operators *are* functions - there's no
relevant distinction there. sizeof is a unary operator, and it
operates on its argument, mapping from the domain that's the union of
{identifiers naming complete types} and {identifiers naming objects
of complete type}, to the range [0,SIZE_MAX].
Not just identifiers. It accepts the union of parenthesized type-name,
which is approximately an abstract declaration, with unary-expression
which would evaluate if executed (except for VLA) to an lvalue
(object) *or (r)value* of complete type, including as one case a
parenthesized (general-)expression. The things it's *useful* to get
the size of are usually lvalues and objects, and often simply
identified ones, but it's not limited to that.

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top