sizeof(Struct::Member) rationale

Discussion in 'C++' started by petschy, Sep 2, 2008.

  1. petschy

    petschy Guest

    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
     
    petschy, Sep 2, 2008
    #1
    1. Advertising

  2. petschy

    Ian Collins Guest

    petschy wrote:
    > 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?

    --
    Ian Collins.
     
    Ian Collins, Sep 2, 2008
    #2
    1. Advertising

  3. petschy

    petschy Guest

    > 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
     
    petschy, Sep 2, 2008
    #3
  4. petschy

    Ian Collins Guest

    petschy wrote:
    >> 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.
    >

    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.

    --
    Ian Collins.
     
    Ian Collins, Sep 2, 2008
    #4
  5. petschy

    petschy Guest

    > 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
     
    petschy, Sep 2, 2008
    #5
  6. petschy wrote:
    > 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.
     
    Juha Nieminen, Sep 2, 2008
    #6
  7. petschy

    Triple-DES Guest

    On 2 Sep, 22:42, petschy <> wrote:
    > 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
     
    Triple-DES, Sep 3, 2008
    #7
  8. petschy

    James Kanze Guest

    On Sep 2, 11:31 pm, Ian Collins <> wrote:
    > petschy wrote:
    > >> 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.


    > 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.)

    --
    James Kanze (GABI Software) email:
    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
     
    James Kanze, Sep 3, 2008
    #8
  9. petschy

    petschy Guest

    petschy, Sep 3, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexander Grigoriev
    Replies:
    0
    Views:
    390
    Alexander Grigoriev
    Sep 12, 2003
  2. Rafal Dabrowa

    sizeof(struct::member)

    Rafal Dabrowa, May 23, 2005, in forum: C++
    Replies:
    3
    Views:
    4,612
    Rafal Dabrowa
    May 24, 2005
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,393
    Chris Fogelklou
    Apr 20, 2004
  4. ziman137
    Replies:
    11
    Views:
    757
    Maxim Yegorushkin
    May 19, 2006
  5. Noob
    Replies:
    25
    Views:
    1,487
    Nick Keighley
    Dec 9, 2009
Loading...

Share This Page