forward declaration for typedef of unnamed structs

Discussion in 'C++' started by Jordi Vilar, Feb 18, 2004.

  1. Jordi Vilar

    Jordi Vilar Guest

    Hi all,

    Is it possible to do a forward declaration for a typedef of an
    incomplete anonymous struct? for example, if I have a type declared
    (in a 3rd part header file that I cannot modify) as:

    typedef struct
    {
    ...
    } mytype;

    how can I forward declare such mytype type?

    thanks in advance,

    Jordi Vilar
    Jordi Vilar, Feb 18, 2004
    #1
    1. Advertising

  2. "Jordi Vilar" <> wrote in message
    news:...
    > Is it possible to do a forward declaration for a typedef of an
    > incomplete anonymous struct? for example, if I have a type declared
    > (in a 3rd part header file that I cannot modify) as:
    >
    > typedef struct
    > {
    > ...
    > } mytype;
    >
    > how can I forward declare such mytype type?


    You could if the structure had a tag. You are in bad luck with anonymous
    structures. One more reason to avoid typedefing structures.

    Peter
    Peter Pichler, Feb 18, 2004
    #2
    1. Advertising

  3. "Peter Pichler" <> wrote in message:

    > >
    > > typedef struct
    > > {
    > > ...
    > > } mytype;
    > >
    > > how can I forward declare such mytype type?

    >
    > You could if the structure had a tag. You are in bad luck with

    anonymous
    > structures. One more reason to avoid typedefing structures.
    >


    At best, this is one more reason to avoid anonymous structures.

    Jonathan
    Jonathan Turkanis, Feb 18, 2004
    #3
  4. Jordi Vilar

    Squider Guest

    Jordi Vilar wrote:

    > Hi all,
    >
    > Is it possible to do a forward declaration for a typedef of an
    > incomplete anonymous struct? for example, if I have a type declared
    > (in a 3rd part header file that I cannot modify) as:
    >
    > typedef struct
    > {
    > ...
    > } mytype;
    >
    > how can I forward declare such mytype type?
    >
    > thanks in advance,
    >
    > Jordi Vilar


    Maybe the author had something that seemed to be a good reason to
    make it anonymous and to have only one of them running around.

    --
    Jukka Helle (Squider) <http://squidysoft.tk/>
    Squider, Feb 18, 2004
    #4
  5. Jordi Vilar

    Derk Gwen Guest

    (Jordi Vilar) wrote:
    # Hi all,
    #
    # Is it possible to do a forward declaration for a typedef of an
    # incomplete anonymous struct? for example, if I have a type declared
    # (in a 3rd part header file that I cannot modify) as:
    #
    # typedef struct
    # {
    # ...
    # } mytype;
    #
    # how can I forward declare such mytype type?

    typedef struct A A;
    typedef struct B B;

    struct A {
    B *b;
    };
    struct B {
    A *a;
    };

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    We found a loophole; they can't keep us out anymore.
    Derk Gwen, Feb 18, 2004
    #5
  6. "Derk Gwen" <> wrote in message
    news:...
    > (Jordi Vilar) wrote:
    > # Hi all,
    > #
    > # Is it possible to do a forward declaration for a typedef of an
    > # incomplete anonymous struct? for example, if I have a type

    declared
    > # (in a 3rd part header file that I cannot modify) as:
    > #
    > # typedef struct
    > # {
    > # ...
    > # } mytype;
    > #
    > # how can I forward declare such mytype type?
    >
    > typedef struct A A;
    > typedef struct B B;
    >
    > struct A {
    > B *b;
    > };
    > struct B {
    > A *a;
    > };
    >


    How does this solve the original problem?

    Jonathan
    Jonathan Turkanis, Feb 18, 2004
    #6
    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. qazmlp
    Replies:
    1
    Views:
    593
    Jonathan Turkanis
    Feb 15, 2004
  2. Plok Plokowitsch

    forward declaration vs. typedef

    Plok Plokowitsch, May 30, 2005, in forum: C++
    Replies:
    2
    Views:
    13,266
    Donovan Rebbechi
    May 30, 2005
  3. Jordi Vilar
    Replies:
    5
    Views:
    17,823
    Jonathan Turkanis
    Feb 18, 2004
  4. Mohammad Omer Nasir
    Replies:
    8
    Views:
    4,203
    Dave Rahardja
    Feb 19, 2007
  5. eliben

    forward declaration of a struct typedef

    eliben, Jan 9, 2009, in forum: C Programming
    Replies:
    6
    Views:
    2,496
    eliben
    Jan 10, 2009
Loading...

Share This Page