Shortcut for accessing build-in struct

Discussion in 'C Programming' started by kenchu.osu@gmail.com, Oct 29, 2007.

  1. Guest

    Hi folks,

    I have a question about accessing the member of a build-in struct.

    Eg.

    struct {
    struct {
    int x;
    int y;
    } pt;
    int ...
    ...
    } info;

    I remember there is a method to simplify the access of info.pt.x using
    info.x, but I cannot recall that. Can you guys help me with that?

    Thanks a lot.

    Best,
    Ken
     
    , Oct 29, 2007
    #1
    1. Advertising

  2. Eric Sosman Guest

    wrote On 10/29/07 11:55,:
    > Hi folks,
    >
    > I have a question about accessing the member of a build-in struct.
    >
    > Eg.
    >
    > struct {
    > struct {
    > int x;
    > int y;
    > } pt;
    > int ...
    > ...
    > } info;
    >
    > I remember there is a method to simplify the access of info.pt.x using
    > info.x, but I cannot recall that. Can you guys help me with that?


    Some compilers allow "anonymous" struct elements, but
    this is not permitted in Standard C (except for a special
    case involving bit-fields, not applicable here).

    You could play preprocessor games, like

    #define X(s) ((s).pt.x)

    .... but in my experience such tricks are usually more
    trouble than they're worth.

    --
     
    Eric Sosman, Oct 29, 2007
    #2
    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. RA Scheltema
    Replies:
    3
    Views:
    424
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    837
  3. DanielEKFA
    Replies:
    8
    Views:
    642
    DanielEKFA
    May 16, 2005
  4. James Harris
    Replies:
    4
    Views:
    1,462
    James Harris
    Oct 9, 2003
  5. Chris Fogelklou
    Replies:
    36
    Views:
    1,445
    Chris Fogelklou
    Apr 20, 2004
Loading...

Share This Page