DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   External Delaration for An Array? (http://www.daniweb.com/forums/thread158609.html)

lehe Nov 20th, 2008 2:29 pm
External Delaration for An Array?
 
Hi,
I have an array. I put its definition in a .c file and externally delare it in a .h file like this:
//.c file
unsigned char jetmap[][]={
{0, 207, 255},
{0, 223, 255},
{0, 239, 255},
{0, 255, 255},
{16, 255, 239},
{32, 255, 223},
{48, 255, 207},
{64, 255, 191},
{80, 255, 175}
}
...
//.h file
extern unsigned char jetmap[][]; //missing subscript
// extern unsigned char ** jetmap; // redefinition; different types of indirection

As in the comment of the header file, both declarations are reported wrong by complier. How to delare the correct type of an array? Thanks in advance!

Narue Nov 20th, 2008 3:10 pm
Re: External Delaration for An Array?
 
>extern unsigned char jetmap[][]; //missing subscript
Yep, you're required to specify all but the first dimension, even for an incomplete type. You need it in the definition too:
/* .c file */
unsigned char jetmap[][3] = { /* ... */ };

/* .h file */
extern unsigned char jetmap[][3];
>extern unsigned char ** jetmap; // redefinition; different types of indirection
Yep, the declaration doesn't match the definition. The type of jetmap in the definition is
unsigned char (*)[3]
.

lehe Nov 20th, 2008 3:47 pm
Re: External Delaration for An Array?
 
Thank you!


All times are GMT -4. The time now is 7:58 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC