Topic: Paragraphs 5.17-3 and 5.17-7
Author: AlbertoBarbati@libero.it (Alberto Ganesh Barbati)
Date: Tue, 3 Jul 2007 13:10:53 GMT Raw View
petek1976 ha scritto:
> Are these statements in contradiction with each other?
>
> Quote:
>
> 5.17-3 "If the left operand is not of class type, the expression is
> implicitly converted (clause 4) to the cv-unqualified type of the left
> operand"
>
> 5.17-7 "The behavior of an expression of the form E1 op= E2 is
> equivalent to E1 = E1 op E2 except that E1 is evaluated only once. In
> += and -=, E1 shall either have arithmetic type or be a pointer to a
> possibly cvqualified completely defined object type. In all other
> cases, E1 shall have arithmetic type"
I don't see any contradiction. Could you explain what you have in mind?
>
> So what is the correct result of int i=5; i /= 1.5; ?
>
1) the value of i is first converted to double (5.6/2, 5/9 e 4.9/2)
2) the division 5.0 / 1.5 is evaluated to 3.333333...
3) i is assigned the value 3 (4.9/1)
The result of the expression is an lvalue of type int whose value is 3.
Ganesh
---
[ 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://www.comeaucomputing.com/csc/faq.html ]
Author: petek1976 <pete.karousos@earthlink.net>
Date: Mon, 2 Jul 2007 11:28:05 CST Raw View
Are these statements in contradiction with each other?
Quote:
5.17-3 "If the left operand is not of class type, the expression is
implicitly converted (clause 4) to the cv-unqualified type of the left
operand"
5.17-7 "The behavior of an expression of the form E1 op= E2 is
equivalent to E1 = E1 op E2 except that E1 is evaluated only once. In
+= and -=, E1 shall either have arithmetic type or be a pointer to a
possibly cvqualified completely defined object type. In all other
cases, E1 shall have arithmetic type"
So what is the correct result of int i=5; i /= 1.5; ?
---
[ 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://www.comeaucomputing.com/csc/faq.html ]