How to declare extern typedef struct?

Discussion in 'C Programming' started by Dirk Bruere at NeoPax, Dec 6, 2008.

  1. Dirk Bruere at NeoPax, Dec 6, 2008
    #1
    1. Advertising

  2. In article <>,
    Dirk Bruere at NeoPax <> wrote:

    >I've got a bit of code in one .c file:
    >
    >typedef struct
    >{
    > SAMPLE_TYPE a0, a1, a2, a3, a4;
    > SAMPLE_TYPE x1, x2, y1, y2;
    >} biquad;


    That just declares a type, not an object.

    >How do I declare it as an extern in another .c file that uses the
    >definition?


    If you meant to declare a type, put it in a .h file included in both
    ..c files. If you meant to declare an object, declare the struct in a
    ..h file and either declare the object (with "extern") there too or in
    the other .c file.

    -- Richard
    --
    Please remember to mention me / in tapes you leave behind.
     
    Richard Tobin, Dec 6, 2008
    #2
    1. Advertising

  3. Richard Tobin wrote:
    > In article <>,
    > Dirk Bruere at NeoPax <> wrote:
    >
    >> I've got a bit of code in one .c file:
    >>
    >> typedef struct
    >> {
    >> SAMPLE_TYPE a0, a1, a2, a3, a4;
    >> SAMPLE_TYPE x1, x2, y1, y2;
    >> } biquad;

    >
    > That just declares a type, not an object.
    >
    >> How do I declare it as an extern in another .c file that uses the
    >> definition?

    >
    > If you meant to declare a type, put it in a .h file included in both
    > .c files. If you meant to declare an object, declare the struct in a
    > .h file and either declare the object (with "extern") there too or in
    > the other .c file.
    >
    > -- Richard


    Yes - it's so obvious once I know!
    Thanks.
    Another Sat night, another modafinil and on with the work... and
    Wolfenstein online...

    --
    Dirk

    http://www.transcendence.me.uk/ - Transcendence UK
    http://www.theconsensus.org/ - A UK political party
    http://www.onetribe.me.uk/wordpress/?cat=5 - Our podcasts on weird stuff
     
    Dirk Bruere at NeoPax, Dec 6, 2008
    #3
  4. Dirk Bruere at NeoPax

    CBFalconer Guest

    Dirk Bruere at NeoPax wrote:
    >
    > I've got a bit of code in one .c file:
    >


    _______ file biquad.h ________
    > typedef struct
    > {
    > SAMPLE_TYPE a0, a1, a2, a3, a4;
    > SAMPLE_TYPE x1, x2, y1, y2;
    > } biquad;

    _______ EOF file biquad.h _______
    >
    > How do I declare it as an extern in another .c file that uses
    > the definition?


    Now put #include "biquad.h" in each .c file that needs it. You
    will also need to define SAMPLE_TYPE.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
     
    CBFalconer, Dec 7, 2008
    #4
  5. CBFalconer wrote:
    > Dirk Bruere at NeoPax wrote:
    >> I've got a bit of code in one .c file:
    >>

    >
    > _______ file biquad.h ________
    >> typedef struct
    >> {
    >> SAMPLE_TYPE a0, a1, a2, a3, a4;
    >> SAMPLE_TYPE x1, x2, y1, y2;
    >> } biquad;

    > _______ EOF file biquad.h _______
    >> How do I declare it as an extern in another .c file that uses
    >> the definition?

    >
    > Now put #include "biquad.h" in each .c file that needs it. You
    > will also need to define SAMPLE_TYPE.
    >


    That's how I did it.
    Thanks to all.

    --
    Dirk

    http://www.transcendence.me.uk/ - Transcendence UK
    http://www.theconsensus.org/ - A UK political party
    http://www.onetribe.me.uk/wordpress/?cat=5 - Our podcasts on weird stuff
     
    Dirk Bruere at NeoPax, Dec 7, 2008
    #5
    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. DanielEKFA
    Replies:
    8
    Views:
    641
    DanielEKFA
    May 16, 2005
  2. Steven T. Hatton
    Replies:
    2
    Views:
    697
  3. Jens Thoms Toerring

    Re: extern typedef struct

    Jens Thoms Toerring, May 18, 2010, in forum: C Programming
    Replies:
    0
    Views:
    652
    Jens Thoms Toerring
    May 18, 2010
  4. Seebs

    Re: extern typedef struct

    Seebs, May 18, 2010, in forum: C Programming
    Replies:
    3
    Views:
    591
    Jens Thoms Toerring
    May 18, 2010
  5. BruceS

    Re: extern typedef struct

    BruceS, May 18, 2010, in forum: C Programming
    Replies:
    6
    Views:
    1,058
    BruceS
    May 19, 2010
Loading...

Share This Page