Topic: sizeof(a,b)


Author: fjh@cs.mu.OZ.AU (Fergus Henderson)
Date: 2000/08/11
Raw View
James Kuyper <kuyper@wizard.net> writes:

 >I think there's something I'm seriously misunderstanding about the C++
 >standard. In describing the various types of expressions, it will
 >frequently state that the lvalue-to-rvalue, array-to-pointer, and
 >function-to-pointer conversions are NOT applied for a given operand.
 >This gives the impression that those conversions are applied to all
 >operands by default unless explicitly stated otherwise. However, I can't
 >find any statement to that effect.
 >It does say that those conversions are applied "Whenever an lvalue
 >expression appears as an operand of an operator that expects an rvalue
 >for that operand". However, I can't find any places where the C++
 >standard explicitly says that any given operator expects an rvalue for
 >any given operand, except for a non-normative example in 3.10p4 which
 >identifies unary and binary + as operands requiring an rvalue. However,
 >there's no text in the normative description of unary and binary + which
 >says so explicitly. Is there some indirect method the standard uses to
 >indicate this?

I couldn't find any.  Clearly the intent is that unless otherwise stated,
every operator expects its operands to be rvalues, and thus the
lvalue-to-rvalue, array-to-pointer, and function-to-pointer conversions
are applied.  However, even though this is clearly the intent, as far
as I could see it is not stated explicitly in the normative text of
the standard.

--
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3        |     -- the last words of T. S. Garp.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: James Kuyper <kuyper@wizard.net>
Date: 2000/08/10
Raw View
"Clive D.W. Feather" wrote:
>
> In article <39919144.551D192@tribble.com>, David R Tribble
> <david@tribble.com> writes

[a is an array]

> >>> I'm pretty certain that 'sizeof(i,a)' is exactly the same as
> >>> 'sizeof(a)'.
> >> No.
> >Then this is yet another gratuitous incompatibility with C++.
>
> Then blame the C++ people, because this hasn't changed in C.
>
> But are you sure you are interpreting the C++ standard correctly ? The
> same subtlety may be involved: in (i,a), a is an operand of comma and is
> converted to a pointer.

The C++ standard says that the array-to-pointer conversion is not
performed on the left operand of a comma operator, but it also doesn't
say that the array-to-pointer conversion IS performed on the right
operand.
I think there's something I'm seriously misunderstanding about the C++
standard. In describing the various types of expressions, it will
frequently state that the lvalue-to-rvalue, array-to-pointer, and
function-to-pointer conversions are NOT applied for a given operand.
This gives the impression that those conversions are applied to all
operands by default unless explicitly stated otherwise. However, I can't
find any statement to that effect.
It does say that those conversions are applied "Whenever an lvalue
expression appears as an operand of an operator that expects an rvalue
for that operand". However, I can't find any places where the C++
standard explicitly says that any given operator expects an rvalue for
any given operand, except for a non-normative example in 3.10p4 which
identifies unary and binary + as operands requiring an rvalue. However,
there's no text in the normative description of unary and binary + which
says so explicitly. Is there some indirect method the standard uses to
indicate this?

The C standard uses "rvalue" only once, in a note indicating that this
is an alternate way of referring to the "value of the expression". If
that were also stated in the C++ standard it would resolve my confusion
- it frequently refers to the value of an operand.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]