Define Array in C

Well... you certainly don't need to use a define. Just add them into the header as const, static arrays.

/* prevents multiple, redundant includes */
/* make sure to use a symbol that is fairly sure to be unique */
#ifndef TEST_H
#define TEST_H

/* your image data */
const char image[] = { 1, 2, 3, 4, ... };

#endif

Also, if you want help on a compilation error then you should post your code.


Because you are displaying on an LCD, I am assuming this is an embedded system.

Don't put the data into a header.

Put the data into an ordinary C or C++ file. Compile this. It might only contain the data, that is okay, and makes it easy to update.

Then use the header file to give access to the data.

For example, in a images.c file:

#include "images.h"
const byte numbers1[MAX_NUMBERS1] = { ... };
byte numbers2[MAX_NUMBERS2];       // will be initialsied to 0

Then images.h is:

#ifndef _IMAGES_H_
#define _IMAGES_H_

typedef unsigned char byte;
#define MAX_NUMBERS1 (450)
        // different constants in case you change something        
#define MAX_NUMBERS2 (450)      
       // even better if you can do const static int MAX_NUMBERS1=450; 
       // but depends on the compiler
extern const byte numbers1[MAX_NUMBERS1] = { ... };
extern byte numbers2[MAX_NUMBERS2];       // will be initialised to 0

#endif

Then all other .c files in the program can access them.

It is (almost) always a bad idea to put a definition of a variable into a header file.

A declaration of a variable, eg. extern byte numbers2[MAX_NUMBERS2]; is telling the C compiler that there is an array variable called numbers2 somewhere else in the final, linked program. If the linker doesn't get that definition (from somewhere else) then it will raise an error because there is no space for the variable allocated.

A definition of a variable (notice no extern), eg. byte numbers2[MAX_NUMBERS2]; is effectively telling the C compiler that there is an array variable called numbers2 and it should allocate the space here, in the resulting object code from this source file, and this will be used to hold the value of the variable in the final, linked program.

The space for numbers2 is not allocated by the C compiler when it sees a declaration (preceded by extern), it is allocated when it sees the actual definition (no extern).

So, if you put the actual definition of any variable in a header file, and include it into more than one source code files (.c), the C compiler will allocate space for the variable more than once. Then the linker will give an error (usually multiple definitions of the same name).

There is a more subtle problem. If, when first developing the program, the header file is only included is one source file, then the program will compile and link correctly. Then, at a later date, if a second source file includes the header (maybe someone has just split the original source code file into two files), the linker will raise a 'multiple definitions' error. This can be very confusing because the program used to compile and link, and apparently nothing has changed.

Summary
Never allocate space for a variable by putting a definition in a header file. Only put variable declarations in header files.