How to declare extern 2d-array in header?

江枫思渺然 提交于 2019-12-05 02:39:31

You need, at a minimum, to include the right-most column size for a 2-D array. You can declare it like this:

extern unsigned char LCD[][64];

Otherwise the compiler would not be able to compute the offset after the first row.

In C an array does not contain information about the size of each one of its dimensions. Therefore, the compiler needs to know how large is each one of the dimensions except the first one. So, to correct this situation, do something like this:

LCD.h:

#define MINOR 64
extern unsigned char LCD[][MINOR];

LCD.c:

unsigned char LCD[8][MINOR] = {((unsigned char)0)};

(EDIT: sorry, I messed up things in the beginning, fixed it now.)

Try specifying the dimensions of the array. In C for a multidimensional array only one dimension can be left unspecified.

Like this:

extern unsigned char LCD[][64];

With multidimensional arrays, all but the first dimension must be specified. So...

extern unsigned char LCD[][64];

Should do it.

Add to the header file a declaration like:

extern unsigned char LCD[8][64];

sizeof of LCD array will refused if you didn't define the size of the two dimension !

sizeof refused : extern unsigned char LCD[][64];
sizeof accepted : extern unsigned char LCD[8][64];

it depend what you want !

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!