extern declarations help!

Posted by: genixia

extern declarations help! - 07/03/2002 14:19

This is really directed to Mark, although if anyone else can answer, then feel free...

I have added a function to empeg_mixer.c that needs to access a table in hijack.c . The table is of type hijack_db_table_t that is typedef'd in hijack.c

So, I put the following in empeg_mixer.h:

typedef struct hijack_db_table_s {
char *name;
unsigned int dbvalue;
} hijack_db_table_t;

extern const hijack_db_table_t hijack_db_table[25];


but I still get undefined reference errors when linking special.a

By declaring the table as extern in hijack.c as well, everything compiles, links and works, but I get a compiler warning:
hijack.c:411: warning: `hijack_db_table' initialized and declared `extern'

How do I get rid of this warning?
Posted by: mlord

Re: extern declarations help! - 07/03/2002 15:27

Move the typedef to hijack.h ("find . -name hijack.h"), declare the table itself in hijack.c with NO extern or static keywords.

Declare it again as "extern" in empeg_mixer.c

Problem solved.

-ml
Posted by: mlord

Re: extern declarations help! - 07/03/2002 15:28

And don't neglect to "#include <asm/arch/hijack.h>" in empeg_mixer.c
Posted by: genixia

Re: extern declarations help! - 07/03/2002 17:17

Thanks, although I've just seen The Way That I Was Supposed To Do It(tm) - dereference the table in in hijack.c and pass the results as ints in the function call to the function in empeg_mixer.c

This C stuff is fun, but I haven't quite gotten my head around the .h idiosyncracies