Topic: pointer to member functions
Author: ben-public-nospam@decadentplace.org.uk (Ben Hutchings)
Date: Wed, 6 Dec 2006 06:37:30 GMT Raw View
On 2006-12-01, James Kanze <james.kanze@gmail.com> wrote:
> Ron Natalie wrote:
<snip>
>> Note that VC++ is in violation of the standard on this
>> feature with certain compiler settings because with those
>> settings (which are the default) the pointers to members are
>> different sizes depending on the inheritance hierarchy involved.
>
> Actually, I'm not sure if you can invoke that reason per se; I
> don't think that the standard really requires that all pointer
> to member functions have the same size (although it probably
> should).
<snip>
Any pointer to member data can be converted to any other such type and
back without data loss, and similarly for pointers to member functions
(5.2.10/9). This implies that within each set of member pointer types
all types have the same number of value bits, if not the same size.
Regrettably, the "optimising" of pointer-to-member size is the default
behaviour in VC++ and it is necessary to use an option to disable it.
Ben.
--
Ben Hutchings
I haven't lost my mind; it's backed up on tape somewhere.
---
[ 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: kuyper@wizard.net
Date: Wed, 6 Dec 2006 09:38:25 CST Raw View
Ben Hutchings wrote:
.
> Any pointer to member data can be converted to any other such type and
> back without data loss, and similarly for pointers to member functions
> (5.2.10/9). This implies that within each set of member pointer types
> all types have the same number of value bits, if not the same size.
It implies that for each of those categories of pointers-to-member
types, there's a certain minimum number of value bits, sufficient to
represent all values in that category without loss, and that every type
in one of those categories must have at least that many value bits.
However, nothing prohibits some pointer-to-member types from using a
representation that is more redundant than other pointer-to-member
types, so long as the conversions between them take that difference in
representation into account.
I can't imagine any reason why an implementation would do that, but it
would be legal.
---
[ 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: "James Kanze" <james.kanze@gmail.com>
Date: Wed, 6 Dec 2006 11:44:35 CST Raw View
Ben Hutchings wrote:
> On 2006-12-01, James Kanze <james.kanze@gmail.com> wrote:
> > Ron Natalie wrote:
> <snip>
> >> Note that VC++ is in violation of the standard on this
> >> feature with certain compiler settings because with those
> >> settings (which are the default) the pointers to members are
> >> different sizes depending on the inheritance hierarchy involved.
> > Actually, I'm not sure if you can invoke that reason per se; I
> > don't think that the standard really requires that all pointer
> > to member functions have the same size (although it probably
> > should).
> <snip>
> Any pointer to member data can be converted to any other such type and
> back without data loss, and similarly for pointers to member functions
> (5.2.10/9). This implies that within each set of member pointer types
> all types have the same number of value bits, if not the same size.
This is what I had in mind when I said that I didn't think that
it "really requires that all pointer to member functions have
the same size". The fact that you can convert freely between
them means that there probably isn't a reasonable implementation
where they don't have the same size, but the standard doesn't
really say as much. (As you say, they could have a different
number of padding bits, although I can't for the love of me
think of any reason why this should possibly be the case.)
> Regrettably, the "optimising" of pointer-to-member size is the default
> behaviour in VC++ and it is necessary to use an option to disable it.
By default, RTTI is off, and I don't think exception handling is
standard either. By default, G++ supports VLA's, and probably a
couple of other extensions. By default, I don't know of any C++
compiler which is conform without a few options. (Although you
have to admit that the choice here seems incredibly stupid. Do
any programs even exist where the size of pointer to member
functions is critical, and must be optimized? As far as I know,
no other vendor even bothers to offer this optimization as an
option.)
--
James Kanze (GABI Software) email:james.kanze@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
---
[ 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: "James Kanze" <james.kanze@gmail.com>
Date: Fri, 1 Dec 2006 16:57:43 CST Raw View
Ron Natalie wrote:
> jam wrote:
> > again on Microsft vc++ :pointer to member functions are castable
> > neither to integral types nor to none-member function pointers .I am
> > using unions for this purpose.
> And your question is? You can't store pointer-to-members into
> normal pointers frequently because they require MORE information
> than will fit. Ever do a sizeof() on a pointer-to-member? I
> bet it is at least TWICE as large as the corresponding straight
> pointer.
> There is nothing strange about VC++ in this regard. The standard
> doesn't provide for reinterpret casting of pointer-to-member to
> either integral type or other pointer types. The only thing
> it does provide for is for casting to other pointer-to-member
> types. Note that VC++ is in violation of the standard on this
> feature with certain compiler settings because with those
> settings (which are the default) the pointers to members are
> different sizes depending on the inheritance hierarchy involved.
Actually, I'm not sure if you can invoke that reason per se; I
don't think that the standard really requires that all pointer
to member functions have the same size (although it probably
should). The reason VC++ is in violation is that if you define
pointer to member functions in two different compilation units,
with an incomplete type in one, and a complete type in the
other, with certain inheritance hierarchies, the generated code
simply doesn't work. In short, they generate bad code for a
legal C++ program.
--
James Kanze (Gabi Software) email: james.kanze@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
---
[ 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: "jam" <farid.mehrabi@gmail.com>
Date: Thu, 30 Nov 2006 17:01:42 CST Raw View
again on Microsft vc++ :pointer to member functions are castable
neither to integral types nor to none-member function pointers .I am
using unions for this purpose.
regards
FM
---
[ 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: ron@spamcop.net (Ron Natalie)
Date: Fri, 1 Dec 2006 15:55:23 GMT Raw View
jam wrote:
> again on Microsft vc++ :pointer to member functions are castable
> neither to integral types nor to none-member function pointers .I am
> using unions for this purpose.
>
And your question is? You can't store pointer-to-members into
normal pointers frequently because they require MORE information
than will fit. Ever do a sizeof() on a pointer-to-member? I
bet it is at least TWICE as large as the corresponding straight
pointer.
There is nothing strange about VC++ in this regard. The standard
doesn't provide for reinterpret casting of pointer-to-member to
either integral type or other pointer types. The only thing
it does provide for is for casting to other pointer-to-member
types. Note that VC++ is in violation of the standard on this
feature with certain compiler settings because with those
settings (which are the default) the pointers to members are
different sizes depending on the inheritance hierarchy involved.
---
[ 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 ]