Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to declare extern typedef struct?

Reply
Thread Tools

How to declare extern typedef struct?

 
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      12-06-2008
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;

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

Thanks for previous help!

--
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
 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      12-06-2008
In article <(E-Mail Removed)>,
Dirk Bruere at NeoPax <(E-Mail Removed)> 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.
 
Reply With Quote
 
 
 
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      12-06-2008
Richard Tobin wrote:
> In article <(E-Mail Removed)>,
> Dirk Bruere at NeoPax <(E-Mail Removed)> 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
 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      12-07-2008
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.
 
Reply With Quote
 
Dirk Bruere at NeoPax
Guest
Posts: n/a
 
      12-07-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Difference of extern short *x and extern short x[]? Andre C Programming 5 07-17-2012 07:38 PM
using extern to declare an instance of a class. kid_kei C++ 1 05-12-2006 03:12 PM
Query: How to declare a template class member function 'extern "C"' ? tropostropos@hotmail.com C++ 9 08-03-2005 06:20 PM
extern const char * vs. extern const char []http://tinyurl.com/47e3k Thomas Matthews C++ 5 08-02-2004 10:36 AM



Advertisments