Topic: Is sizeof(pointer-to-member) legal?


Author: Krzysztof Parzyszek <hektor@iname.com>
Date: Wed, 27 Mar 2002 13:30:09 GMT
Raw View
On Tue, 26 Mar 2002 19:59:24 CST, James Kuyper Jr. wrote:
> Krzysztof Parzyszek wrote:
>>
>> I just checked the standard (section 5.3.3) and it doesn't seem like
>> sizeof can be applied to pointers-to-members. ...
>
> I don't follow that. I see no explicit prohibition on it. How did you
> reach that conclusion?

It doesn't mention anything about applying sizeof to such pointers.
As far as 1.3.12 is concerned, we have ``Undefined behavior may also
be expected when this International Standard omits the description
of any explicit definition of behavior.''
In my understanding this would apply to the definition of sizeof
as it lacks any explicit description of application of sizeof
to a pointer to member.  However, I just realized that 5.3.3 doesn't
say anything about applying sizeof to normal pointers (except pointers
to functions), and I wouldn't go as far as saying that sizeof(void*)
is invalid.  I guess I'm missing something, but I'm not sure what...


--
<>> hektor@iname.com <Krzysztof Parzyszek>  Visit http://google.com
<<> (E)-N-[(4-Hydroxy-3-methoxyphenyl)methyl]-8-methyl-6-nonenamide

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Wed, 27 Mar 2002 18:22:10 GMT
Raw View
Krzysztof Parzyszek wrote:
>
> On Tue, 26 Mar 2002 19:59:24 CST, James Kuyper Jr. wrote:
> > Krzysztof Parzyszek wrote:
> >>
> >> I just checked the standard (section 5.3.3) and it doesn't seem like
> >> sizeof can be applied to pointers-to-members. ...
> >
> > I don't follow that. I see no explicit prohibition on it. How did you
> > reach that conclusion?
>
> It doesn't mention anything about applying sizeof to such pointers.

Sure it does: 5.3.3p1: "The sizeof operator yields the number of bytes
in the object representation of its operand."

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Wed, 27 Mar 2002 18:58:31 GMT
Raw View
In article <slrnaa2ll5.du.hektor@antares.stures.iastate.edu>, Krzysztof
Parzyszek <hektor@iname.com> writes
>>> I just checked the standard (section 5.3.3) and it doesn't seem like
>>> sizeof can be applied to pointers-to-members. ...
>>
>> I don't follow that. I see no explicit prohibition on it. How did you
>> reach that conclusion?
>
>It doesn't mention anything about applying sizeof to such pointers

read 5.3.3 para 1. It excludes certain cases (function, incomplete type,
enum until all the enumerators have been declared) other wise sizeof can
be applied to  any and all objects and parenthesised type-ids.
pointer-to-member is such a type, and its value will be such an
expression. Nothing beyond para 1 has any bearing on this issue because
that para. provides the ongoing context for the rest.


--
Francis Glassborow
Check out the ACCU Spring Conference 2002
4 Days, 4 tracks, 4+ languages, World class speakers
For details see: http://www.accu.org/events/public/accu0204.htm

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Steve Clamage <clamage@eng.sun.com>
Date: Wed, 27 Mar 2002 21:26:12 GMT
Raw View
On Tue, 26 Mar 2002, Krzysztof Parzyszek wrote:

>
> I just checked the standard (section 5.3.3) and it doesn't seem like
> sizeof can be applied to pointers-to-members.  According to 1.3.12
> this should cause undefined behavior.  Is that correct?

I don't find anything in 5.3.3 that would make sizeof
pointer-to-member invalid or undefined.  It lists some special
cases as allowed or disallowed, but the remainder are covered
by the "expression or parenthesized type-id" in paragraph 1.

Maybe you could point out what you see as the problem.

--
Steve Clamage, stephen.clamage@sun.com

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Krzysztof Parzyszek <hektor@iname.com>
Date: Wed, 27 Mar 2002 22:05:29 GMT
Raw View
On Wed, 27 Mar 2002 21:26:12 GMT, Steve Clamage wrote:
>
> It lists some special
> cases as allowed or disallowed, but the remainder are covered
> by the "expression or parenthesized type-id" in paragraph 1.
>
> Maybe you could point out what you see as the problem.

It explicitly mentions pointers to functions (as opposed to
fuctions themselves) and that made me look for an explicit
definition of application to pointers to members.  I overlooked
that sentence in paragraph 1.  My fault.

Thanks to all who replied.


--
<>> hektor@iname.com <Krzysztof Parzyszek>  Visit http://google.com
<<> (E)-N-[(4-Hydroxy-3-methoxyphenyl)methyl]-8-methyl-6-nonenamide

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Krzysztof Parzyszek <hektor@iname.com>
Date: Tue, 26 Mar 2002 15:53:46 GMT
Raw View
I just checked the standard (section 5.3.3) and it doesn't seem like
sizeof can be applied to pointers-to-members.  According to 1.3.12
this should cause undefined behavior.  Is that correct?


--
<>> hektor@iname.com <Krzysztof Parzyszek>  Visit http://google.com
<<> (E)-N-[(4-Hydroxy-3-methoxyphenyl)methyl]-8-methyl-6-nonenamide

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Tue, 26 Mar 2002 19:59:24 CST
Raw View
Krzysztof Parzyszek wrote:
>
> I just checked the standard (section 5.3.3) and it doesn't seem like
> sizeof can be applied to pointers-to-members. ...

I don't follow that. I see no explicit prohibition on it. How did you
reach that conclusion?

> ...  According to 1.3.12
> this should cause undefined behavior.  Is that correct?

No, it's just implementation-defined, like most other sizeof()'s.

---
[ 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.research.att.com/~austern/csc/faq.html                ]