sizeof(Struct::Member) rationale

P

petschy

Hello All,

I confronted recently with the fact that the size of a struct member
can't be determined with sizeof(Struct::Member). I'm aware of the
alternative methods to do this, however, I'm interested in the
rationale why the Struct::Member syntax is disallowed.

Thanks, P
 
I

Ian Collins

petschy said:
Hello All,

I confronted recently with the fact that the size of a struct member
can't be determined with sizeof(Struct::Member). I'm aware of the
alternative methods to do this, however, I'm interested in the
rationale why the Struct::Member syntax is disallowed.
Was it even proposed?

If so, what benefits would it bring?
 
P

petschy

Was it even proposed?

I don't know.
If so, what benefits would it bring?

I needed the size of a member, without an actual instance and the
syntax 'felt' natural. This could be done, so I just wondered why is
it disallowed.

P
 
I

Ian Collins

petschy said:
I don't know.


I needed the size of a member, without an actual instance and the
syntax 'felt' natural. This could be done, so I just wondered why is
it disallowed.
In order to see the member, you have to be able to see its type, so why
not take the size of the type?

Something that hasn't been asked for can't be disallowed.
 
P

petschy

In order to see the member, you have to be able to see its type, so why
not take the size of the type?

Yes, that works, but then I need to remember the type of the member,
which the compiler knows anyway. Also, with arrays things get even
more uncomfortable if I want to use the type for the size. Luckily,
sizeof(Struct().Member) works, so my question was rather theoretical
than practical.

Thanks, P
 
J

Juha Nieminen

petschy said:
I confronted recently with the fact that the size of a struct member
can't be determined with sizeof(Struct::Member). I'm aware of the
alternative methods to do this, however, I'm interested in the
rationale why the Struct::Member syntax is disallowed.

AFAIK, it will be allowed in the next standard.
 
T

Triple-DES

Hello All,

I confronted recently with the fact that the size of a struct member
can't be determined with sizeof(Struct::Member). I'm aware of the
alternative methods to do this, however, I'm interested in the
rationale why the Struct::Member syntax is disallowed.

Thanks, P

Hi. As Juha pointed out, this is already in the draft for the next
standard, but that does not really answer your question :).

You may find these links interesting:

http://www.open-std.org/JTC1/sc22/wg21/docs/cwg_defects.html#198
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2253.html

DP
 
J

James Kanze

In order to see the member, you have to be able to see its
type, so why not take the size of the type?

Because you're in a template, and the requirement is that the
instantiation type have a member named toto? (Just guessing.
I've never needed it either.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top