typedef forward declare - Linux

This is a discussion on typedef forward declare - Linux ; Hi, With keyword struct, we can simply do forward declare by: struct struct_a; but if we typedef it: typdef struct struct_a struct_a_t; When we need to use struct_a_t but the cross include occurs, how to tell compiler that struct_a_t is ...

+ Reply to Thread
Results 1 to 14 of 14

Thread: typedef forward declare

  1. typedef forward declare

    Hi,

    With keyword struct, we can simply do forward declare by:

    struct struct_a;

    but if we typedef it:

    typdef struct struct_a struct_a_t;

    When we need to use struct_a_t but the cross include occurs, how to
    tell compiler that struct_a_t is a type? seems like:

    type struct_a_t;

    Thanks.
    ABAI
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  2. Re: typedef forward declare

    Hi Binary(nice one ),

    Usually u wud declare the typedef part in a header
    file,and include that header file in all the filese.When each file is
    compiled,the header info gets included at preprocessing stage and hence
    ur typedefnition.Thats how the complier would get to know about the
    typedef as datatype.

    cheers,
    Kaushal.

    Binary wrote:
    > Hi,
    >
    > With keyword struct, we can simply do forward declare by:
    >
    > struct struct_a;
    >
    > but if we typedef it:
    >
    > typdef struct struct_a struct_a_t;
    >
    > When we need to use struct_a_t but the cross include occurs, how to
    > tell compiler that struct_a_t is a type? seems like:
    >
    > type struct_a_t;
    >
    > Thanks.
    > ABAI
    > --
    > comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    > have an appropriate newsgroups line in your header for your mail to be seen,
    > or the newsgroup name in square brackets in the subject line. Sorry.

    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  3. Re: typedef forward declare

    You didn't get my meaning. Suppose a cross include,
    a.h:

    typedef struct a a_t;

    struct a {
    b_t *b;
    };

    b.h:
    #include "a.h"
    typedef struct b b_t;

    struct b {
    a_t *a;
    };

    When compiler sees include "a.h", it will insert the content of a.h to,
    but it will find that b_t undeclared.

    How to solve such problem? Don't tell me to change b_t to struct b in
    a.h, this can work, but is not what I want to do.

    Thanks.
    ABAI


    On Dec 16, 6:58 am, "krishna" wrote:
    > Hi Binary(nice one ),
    >
    > Usually u wud declare the typedef part in a header
    > file,and include that header file in all the filese.When each file is
    > compiled,the header info gets included at preprocessing stage and hence
    > ur typedefnition.Thats how the complier would get to know about the
    > typedef as datatype.
    >
    > cheers,
    > Kaushal.
    >
    >
    >
    > Binary wrote:
    > > Hi,

    >
    > > With keyword struct, we can simply do forward declare by:

    >
    > > struct struct_a;

    >
    > > but if we typedef it:

    >
    > > typdef struct struct_a struct_a_t;

    >
    > > When we need to use struct_a_t but the cross include occurs, how to
    > > tell compiler that struct_a_t is a type? seems like:

    >
    > > type struct_a_t;

    >
    > > Thanks.
    > > ABAI
    > > --
    > > comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
    > > have an appropriate newsgroups line in your header for your mail to be seen,
    > > or the newsgroup name in square brackets in the subject line. Sorry.--

    > comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
    > have an appropriate newsgroups line in your header for your mail to be seen,
    > or the newsgroup name in square brackets in the subject line. Sorry.



  4. Re: typedef forward declare

    Bin Chen wrote:
    > You didn't get my meaning. Suppose a cross include,
    > a.h:
    >
    > typedef struct a a_t;
    >
    > struct a {
    > b_t *b;
    > };
    >
    > b.h:
    > #include "a.h"
    > typedef struct b b_t;
    >
    > struct b {
    > a_t *a;
    > };
    >
    > When compiler sees include "a.h", it will insert the content of a.h to,
    > but it will find that b_t undeclared.
    >
    > How to solve such problem? Don't tell me to change b_t to struct b in
    > a.h, this can work, but is not what I want to do.
    >
    > Thanks.
    > ABAI
    >
    >


    How about:

    typedef struct a a_t;
    typedef struct b b_t;

    struct a {
    b_t *b;
    };

    struct b {
    a_t *a;
    };

    If the two are so inextricably linked, they should be defined together,
    since neither has independent meaning without the other.
    Tim Keck

  5. Re: typedef forward declare

    On 2006-12-16, Bin Chen wrote:
    > You didn't get my meaning. Suppose a cross include,
    > a.h:
    >
    > typedef struct a a_t;
    >
    > struct a {
    > b_t *b;
    > };
    >
    > b.h:
    > #include "a.h"
    > typedef struct b b_t;
    >
    > struct b {
    > a_t *a;
    > };
    >
    > When compiler sees include "a.h", it will insert the content of a.h to,
    > but it will find that b_t undeclared.
    >
    > How to solve such problem? Don't tell me to change b_t to struct b in
    > a.h, this can work, but is not what I want to do.



    change struct a:

    struct a {
    struct b *b;
    };

    now the compoiler knows what sort of pointer a.b is:

    it's a pointer to some sort of struct, not a pointer to a function or to a void*

    on some systems (eg: ms-dos 16-bit medium memory model) data and function pointers
    have different sizes.

    Bye.
    Jasen

  6. Re: typedef forward declare

    On 2006-12-16, Tim Keck wrote:
    > How about:
    >
    > typedef struct a a_t;
    > typedef struct b b_t;
    >
    > struct a {
    > b_t *b;
    > };
    >
    > struct b {
    > a_t *a;
    > };


    yeah or put the typedefs in a separate header file and keep the structs
    separate.


    Bye.
    Jasen

  7. Re: typedef forward declare



    On Dec 17, 7:30 pm, jasen wrote:
    > On 2006-12-16, Bin Chen wrote:
    >
    >
    >
    > > You didn't get my meaning. Suppose a cross include,
    > > a.h:

    >
    > > typedef struct a a_t;

    >
    > > struct a {
    > > b_t *b;
    > > };

    >
    > > b.h:
    > > #include "a.h"
    > > typedef struct b b_t;

    >
    > > struct b {
    > > a_t *a;
    > > };

    >
    > > When compiler sees include "a.h", it will insert the content of a.h to,
    > > but it will find that b_t undeclared.

    >
    > > How to solve such problem? Don't tell me to change b_t to struct b in
    > > a.h, this can work, but is not what I want to do.change struct a:

    >
    > struct a {
    > struct b *b;
    > };
    >
    > now the compoiler knows what sort of pointer a.b is:
    >
    > it's a pointer to some sort of struct, not a pointer to a function or to a void*
    >
    > on some systems (eg: ms-dos 16-bit medium memory model) data and function pointers
    > have different sizes.
    >

    Thanks for all the replies, but I have to say that I have known the
    method that you have mentioned above. So no other keyword to let me
    declare a typedef?
    > Bye.
    > Jasen



  8. Re: typedef forward declare

    uOn 2006-12-17, Bin Chen wrote:
    >
    >
    > On Dec 17, 7:30 pm, jasen wrote:
    >> On 2006-12-16, Bin Chen wrote:
    >>
    >>
    >> struct a {
    >> struct b *b;
    >> };
    >>
    >> now the compoiler knows what sort of pointer a.b is:
    >>
    >> it's a pointer to some sort of struct, not a pointer to a function or to a void*
    >>
    >> on some systems (eg: ms-dos 16-bit medium memory model) data and function pointers
    >> have different sizes.
    >>

    > Thanks for all the replies, but I have to say that I have known the
    > method that you have mentioned above. So no other keyword to let me
    > declare a typedef?


    "typedefs" can be data or function types....

    knowing that something is a pointer to "typedef" isn't enough information.

    Bye.
    Jasen

  9. Re: typedef forward declare

    krishna wrote:
    > Hi Binary(nice one ),
    >
    > Usually u wud


    This is where I usually stop reading.
    I can live with the occasional speling eror, I can live with the obvious
    language Defizit, but kiddie talk in a technical newsgroup is unbearable.
    I hope you never need to ask a question I could answer.
    --
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize
    -- T. Pratchett
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  10. Re: typedef forward declare

    krishna wrote:

    > Hi Binary(nice one ),
    >
    > Usually u wud declare the typedef part in a header
    > file,and include that header file in all the filese.When each file is
    > compiled,the header info gets included at preprocessing stage and hence
    > ur typedefnition.Thats how the complier would get to know about the
    > typedef as datatype.
    >
    > cheers,
    > Kaushal.
    >
    > Binary wrote:
    >> Hi,
    >>
    >> With keyword struct, we can simply do forward declare by:
    >>
    >> struct struct_a;
    >>
    >> but if we typedef it:
    >>
    >> typdef struct struct_a struct_a_t;
    >>
    >> When we need to use struct_a_t but the cross include occurs, how to
    >> tell compiler that struct_a_t is a type? seems like:
    >>
    >> type struct_a_t;
    >>
    >> Thanks.
    >> ABAI
    >> --
    >> comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    >> have an appropriate newsgroups line in your header for your mail to be
    >> seen,
    >> or the newsgroup name in square brackets in the subject line. Sorry.


    Could I ask you to PLEASE refrain from text messaging on usenet? - its
    infuriating to try and read.
    Thanks,
    Eric
    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  11. Re: typedef forward declare

    Josef Moellers wrote:
    > krishna wrote:
    >
    >> Hi Binary(nice one ),
    >>
    >> Usually u wud

    >
    > This is where I usually stop reading.
    > I can live with the occasional speling eror, I can live with
    > the obvious language Defizit, but kiddie talk in a technical
    > newsgroup is unbearable. I hope you never need to ask a
    > question I could answer.


    Many stop even earlier, when they see the rude top-posting.

    --
    Merry Christmas, Happy Hanukah, Happy New Year
    Joyeux Noel, Bonne Annee.
    Chuck F (cbfalconer at maineline dot net)

    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  12. Re: typedef forward declare



    On Jan 4, 2:42 pm, CBFalconer wrote:
    > Josef Moellers wrote:
    > > krishna wrote:

    >
    > >> Hi Binary(nice one ),

    >
    > >> Usually u wud

    >
    > > This is where I usually stop reading.
    > > I can live with the occasional speling eror, I can live with
    > > the obvious language Defizit, but kiddie talk in a technical
    > > newsgroup is unbearable. I hope you never need to ask a
    > > question I could answer.

    > Many stop even earlier, when they see the rude top-posting.


    Sorry, sometimes I am hurry to write the reply and wasn't aware this. I
    will try to avoid this from now on.
    >
    > --
    > Merry Christmas, Happy Hanukah, Happy New Year
    > Joyeux Noel, Bonne Annee.
    > Chuck F (cbfalconer at maineline dot net)
    >
    > --
    > comp.lang.c.moderated - moderation address: c...@plethora.net -- you must
    > have an appropriate newsgroups line in your header for your mail to be seen,
    > or the newsgroup name in square brackets in the subject line. Sorry.



  13. Re: typedef forward declare

    Hi,
    Eric,Francis Glassborow,Giorgos Keramidas thank you for your
    constructive criticism and pointing them out in lucid and soft
    manner.Ill take care not to produce such difficulties for non english
    speakers again.
    Josef Moellers and CBFalconer ,thank you for not reading my post.I
    found your criticisms 'quite' rude.One would appreciate if you both
    would have adopted the manner the above members have guided.
    With all due respects, and the spirit of C,
    -Kaushal.

    CBFalconer wrote:
    > Josef Moellers wrote:
    > > krishna wrote:
    > >
    > >> Hi Binary(nice one ),
    > >>
    > >> Usually u wud

    > >
    > > This is where I usually stop reading.
    > > I can live with the occasional speling eror, I can live with
    > > the obvious language Defizit, but kiddie talk in a technical
    > > newsgroup is unbearable. I hope you never need to ask a
    > > question I could answer.

    >
    > Many stop even earlier, when they see the rude top-posting.
    >
    > --
    > Merry Christmas, Happy Hanukah, Happy New Year
    > Joyeux Noel, Bonne Annee.
    > Chuck F (cbfalconer at maineline dot net)
    >
    > --
    > comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    > have an appropriate newsgroups line in your header for your mail to be seen,
    > or the newsgroup name in square brackets in the subject line. Sorry.

    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

  14. Re: typedef forward declare

    krishna wrote:
    >
    > Eric,Francis Glassborow,Giorgos Keramidas thank you for your
    > constructive criticism and pointing them out in lucid and soft
    > manner.Ill take care not to produce such difficulties for non
    > english speakers again.
    > Josef Moellers and CBFalconer ,thank you for not reading my
    > post.I found your criticisms 'quite' rude.One would appreciate if
    > you both would have adopted the manner the above members have
    > guided. With all due respects, and the spirit of C,


    Well, you appear to be uneducable, since you persist in rude
    top-posting. Whether that is innate stupidity or bad manners is
    not yet known. You are also persisting in excessive cross-posting,
    which is another indication of foolishness. Follow-ups set.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.

    --
    comp.lang.c.moderated - moderation address: clcm@plethora.net -- you must
    have an appropriate newsgroups line in your header for your mail to be seen,
    or the newsgroup name in square brackets in the subject line. Sorry.

+ Reply to Thread