Topic: sizeof ( Result(T::*)(P1,P2,..))
Author: "Bill Wade" <bill.wade@stoner.com>
Date: 1999/10/27 Raw View
Valentin Bonnard wrote in message <380F9491.555@wanadoo.fr>...
>Andrei Alexandrescu wrote:
>
>> What I wanted to say is that given the behavior of reinterpret_cast, all
>> pointers to all member functions of all classes have the same size.
>
>Maybe it's just me, but I can't see the relation between the
>two parts of this sentence.
The standard says (5.2.10/9) that you can reinterpret_cast a pointer to
function member rvalue to any other pointer to function member rvalue and
back to its original type without loss of information.
For this to work all pointer-to-member-function types must be large enough
to hold all of the value-bits of all other pointer-to-member-function types.
I believe Andrei assumed that this implied that all
pointer-to-member-function types must have the same size.
I don't think anything in the standard actually require that different
pointer-to-member types be the same size, but combining (5.2.10/9) with POD
requirements (3.9) means that no pointer-to-member-function has more
"value-bits" than fit in the smallest pointer-to-member function.
I think a perverse implementation could do something like
int (T::*x)();
short (T::*y)() = &T::short_func;
assert(sizeof(x) == 1); // All bits are value bits
assert(sizeof(y) == 2); // All even bits are value bits
x = reinterpret_cast<int (T::*)()>(y); // Bit twiddle to get all value
bits into the output.
y = 0;
y = reinterpret_cast<short (T::*)()>(x); // Bit untwiddle to restore
y's original value
assert(y == &T::short_func);
Except for the first two asserts, this code (with appropriate definitions
for T and assert) should work on all conforming implementations. A perverse
implementation might make the first two asserts work also.
---
[ 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: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/10/25 Raw View
Andrei Alexandrescu wrote:
> What I wanted to say is that given the behavior of reinterpret_cast, all
> pointers to all member functions of all classes have the same size.
Maybe it's just me, but I can't see the relation between the
two parts of this sentence.
--
Valentin Bonnard
---
[ 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: Hyman Rosen <hymie@prolifics.com>
Date: 1999/10/22 Raw View
James.Kanze@dresdner-bank.com writes:
> "Andrei Alexandrescu" <andrewalex@hotmail.com> wrote:
> > It doesn't depend much, given that you can reinterpret_cast back and
> > forth between any two pointer to member functions, and the result is
> > guaranteed to be correct if you reinterpret_cast'd something and then
> > reinterpret_cast it back.
>
> Where is this guaranteed in the standard? And between what and what?
Any two pointer-to-member-function or pointer-to-member-data,
as specified by 5.2.10/9.
---
[ 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.Kanze@dresdner-bank.com
Date: 1999/10/21 Raw View
In article <380aa1df.0@202.66.196.251>,
"Andrei Alexandrescu" <andrewalex@hotmail.com> wrote:
> It doesn't depend much, given that you can reinterpret_cast back and
> forth between any two pointer to member functions, and the result is
> guaranteed to be correct if you reinterpret_cast'd something and then
> reinterpret_cast it back.
Where is this guaranteed in the standard? And between what and what?
The only guarantee I know of is that you can static_cast a pointer to an
object to void* and back to the original type without loss. Even with
normal pointers to functions, there is no such guarantee.
--
James Kanze mailto:James.Kanze@dresdner-bank.com
Conseils en informatique orient e objet/
Beratung in objekt orientierter Datenverarbeitung
Ziegelh ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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.Kanze@dresdner-bank.com
Date: 1999/10/21 Raw View
In article <38094D7B.4A2859B5@yesic.com>,
Nickolay Mladenov <mladenovn@yesic.com> wrote:
> Does sizeof ( Result(T::*)(P1,P2,..) ) depend on the types T, Result,
> P1, ...?
Maybe. The standard makes no requirements one way or another, so an
implementation is free to do what it wants. In practice, however, I can
hardly imagine an implementation where different pointer to member
functions had different sizes.
--
James Kanze mailto:James.Kanze@dresdner-bank.com
Conseils en informatique orient e objet/
Beratung in objekt orientierter Datenverarbeitung
Ziegelh ttenweg 17a, 60598 Frankfurt, Germany Tel. +49(069)63198627
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 1999/10/21 Raw View
What I wanted to say is that given the behavior of reinterpret_cast, all
pointers to all member functions of all classes have the same size.
Andrei
Valentin Bonnard <Bonnard.V@wanadoo.fr> wrote in message
news:380B18EF.7C2@wanadoo.fr...
>
> Andrei Alexandrescu wrote:
>
> > you can reinterpret_cast back and
> > forth between any two pointer to member functions, and the result is
> > guaranteed to be correct if you reinterpret_cast'd something and then
> > reinterpret_cast it back.
>
> So ?
---
[ 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: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 1999/10/21 Raw View
<James.Kanze@dresdner-bank.com> wrote in message
news:7uhtg7$aup$1@nnrp1.deja.com...
> In article <380aa1df.0@202.66.196.251>,
> "Andrei Alexandrescu" <andrewalex@hotmail.com> wrote:
>
> > It doesn't depend much, given that you can reinterpret_cast back
and
> > forth between any two pointer to member functions, and the result
is
> > guaranteed to be correct if you reinterpret_cast'd something and
then
> > reinterpret_cast it back.
>
> Where is this guaranteed in the standard?
I don't remember.
Ronald :o)
P.S. 5.2.10, para 9.
Andrei
---
[ 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: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 1999/10/18 Raw View
It doesn't depend much, given that you can reinterpret_cast back and
forth between any two pointer to member functions, and the result is
guaranteed to be correct if you reinterpret_cast'd something and then
reinterpret_cast it back.
Andrei
Nickolay Mladenov <mladenovn@yesic.com> wrote in message
news:38094D7B.4A2859B5@yesic.com...
Hi, Does sizeof ( Result(T::*)(P1,P2,..) ) depend on the types T,
Result, P1, ...? If yes, how? Is there a max value? Nickolay
moderator's note: HTML encoding deleted. Please do not post html.
Post in plain text. -sdc ] [ 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 ]
---
[ 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: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/10/18 Raw View
Andrei Alexandrescu wrote:
> you can reinterpret_cast back and
> forth between any two pointer to member functions, and the result is
> guaranteed to be correct if you reinterpret_cast'd something and then
> reinterpret_cast it back.
So ?
--
Valentin Bonnard
[ 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 ]