I think this rule is easy to understand. Because I can find the
contexts of applying the rule as follows.
(1)
int* p = 0;
int b1 = sizeof(*p); // OK, b1 = 4, *p would not be evaluated.
(2)
int array[2];
int b2 = sizeof(array); // OK, b2 = 8, array will not be automatically
converted to a pointer to int
(3)
int b3 = sizeof(strlen); // error, strlen will not be automatically
converted to a function pointer.
So far, everything is understandable.
==========================================
However, In 5.18 of the standard, I find a similar rule on comma
operator: "The lvalue-to-rvalue(4.1), array-to-pointer(4.2),and
function-to-pointer(4.3) standard conversions are not applied to the
left expression."
I tried my best to guess the reason of the latter rule, but failed.
Even, I could not find an example to examine the rule.
As far as I know, C99 didn't provide the rule. My confusion lies in
the reason for making such a rule. Could you give me an example
illustrating that some conversions are applied on the left expression
(or the left operand)? I could not find such an example. If there were
no such an example. Why did the standard provide such a rule?
I cannot even see how one would check whether the conversion happens
or not. Since one couldn't check whether the conversion happens or
not, WHY did the C++ standard explicitly provide such a rule which
doesn't exist in the C language standard? What confused me is just the
question.
Any help will be highly appreciated. Thanks in advance.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
extern struct A a;
int main() { return a, 0; }
because the conversion may not be applied to an
object of incomplete type.
> As far as I know, C99 didn't provide the rule. My confusion lies in
> the reason for making such a rule. Could you give me an example
> illustrating that some conversions are applied on the left expression
> (or the left operand)? I could not find such an example. If there were
> no such an example. Why did the standard provide such a rule?
Part of the reason for the rule is to ensure that when someone writes code
such as
(std::cout << foo), bar();
the implementation is not permitted to reject it even though std::cout is
not copyable.
> news:1182447043.8...@x35g2000prf.googlegroups.com...
> > As far as I know, C99 didn't provide the rule. My confusion lies in
> > the reason for making such a rule. Could you give me an example
> > illustrating that some conversions are applied on the left expression
> > (or the left operand)? I could not find such an example. If there were
> > no such an example. Why did the standard provide such a rule?
> Part of the reason for the rule is to ensure that when someone writes code
> such as
> (std::cout << foo), bar();
> the implementation is not permitted to reject it even though std::cout is
> not copyable.
What's the relationship between copiable and the rest? Copiable
has nothing to do with array to pointer or function to pointer
conversions, and for a class type, it doesn't involve an
lvalue to rvalue conversion.
Does lvalue to rvalue conversion apply to class types, anyway?
I can't think of a case where it would. You copy a class by
calling the copy constructor, which means binding to a
reference, and not lvalue to rvalue conversion. In fact, all
legal operations on a class type are "lvalue-neutral", I think.
The only place I see where lvalue-ness plays a role is in
determining whether you can bind to a non-const reference or
not.
(But I've probably overlooked something fundamental.)
--
James Kanze (GABI Software, from CAI) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34