Topic: 5.10.2 (pg. 87) of the standard (why false?)
Author: "Shark" <cpp_shark@yahoo.com>
Date: Tue, 17 Jan 2006 12:43:37 CST Raw View
bool x = (pdl == pdr); //false
My understanding is that pdl and pdr were both uninitialized and hence
the result should be undefined, based on what I know about pointers.
But in paragraph's context I don't see any reason. Can someone explain?
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: AlbertoBarbati@libero.it (Alberto Ganesh Barbati)
Date: Tue, 17 Jan 2006 21:30:54 GMT Raw View
Shark wrote:
> bool x = (pdl == pdr); //false
>
> My understanding is that pdl and pdr were both uninitialized and hence
> the result should be undefined, based on what I know about pointers.
> But in paragraph's context I don't see any reason. Can someone explain?
First of all the example is on page 88 in the 2003 version of the C++
Standard. It was on page 87 in the 1998 version. You should always refer
to the latest version otherwise you might ask for something that has
already been fixed.
Back to the question, let me quote the entire example (with added comments):
struct B {
int f();
};
struct L : B { };
struct R : B { };
struct D : L, R { };
int (B::*pb)() = &B::f;
int (L::*pl)() = pb;
int (R::*pr)() = pb;
int (D::*pdl)() = pl; // <<<<<<<<<<<<<<<<<<<<<<<<
int (D::*pdr)() = pr; // <<<<<<<<<<<<<<<<<<<<<<<<
bool x = (pdl == pdr); // false
the two lines marked with "// <<<<<<<<<<<<<<<<<<<<<<<<" clearly
initialize both pdl and pdr, so what makes you think that they are both
uninitialized?
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.jamesd.demon.co.uk/csc/faq.html ]
Author: v.Abazarov@comAcast.net (Victor Bazarov)
Date: Wed, 18 Jan 2006 03:54:16 GMT Raw View
Shark wrote:
> bool x = (pdl == pdr); //false
>
> My understanding is that pdl and pdr were both uninitialized and hence
What??? 'pdl' is initialised with the value of 'pl', which is in turn
initialised from the value of 'pb', which is initialised from '&B::f'.
The whole point of the example is to show that the conversions are applied
and while both of the pointers are "growing" from the same expression, the
values change because of the conversions.
> the result should be undefined, based on what I know about pointers.
> But in paragraph's context I don't see any reason. Can someone explain?
See above.
V
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]
Author: "Shark" <cpp_shark@yahoo.com>
Date: Wed, 18 Jan 2006 09:51:29 CST Raw View
===================================== MODERATOR'S COMMENT:
Please do not quote more of the original message than is necessary to
provide context. In particular, the material following the last comment
should have been deleted.
---
Steve Clamage, stephen.clamage@sun.com
===================================== END OF MODERATOR'S COMMENT
Victor Bazarov wrote:
> Shark wrote:
> > bool x = (pdl == pdr); //false
> >
> > My understanding is that pdl and pdr were both uninitialized and hence
>
> What??? 'pdl' is initialised with the value of 'pl', which is in turn
> initialised from the value of 'pb', which is initialised from '&B::f'.
> The whole point of the example is to show that the conversions are applied
> and while both of the pointers are "growing" from the same expression, the
> values change because of the conversions.
>
Oh, well my bad. I'll be more careful next time. Thanks Ganesh and
Victor
> > the result should be undefined, based on what I know about pointers.
> > But in paragraph's context I don't see any reason. Can someone explain?
>
> See above.
>
> V
>
> ---
> [ 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.jamesd.demon.co.uk/csc/faq.html ]
---
[ 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.jamesd.demon.co.uk/csc/faq.html ]