As you display on the LCD, I assume this is an embedded system.
Do not put data in the header.
Put the data in a regular C or C ++ file. Compile this. It can only contain data, this is normal and easy to update.
Then use the header file to provide access to the data.
For example, in the images.c file:
#include "images.h" const byte numbers1[MAX_NUMBERS1] = { ... }; byte numbers2[MAX_NUMBERS2];
Then images.h this:
#ifndef _IMAGES_H_ #define _IMAGES_H_ typedef unsigned char byte; #define MAX_NUMBERS1 (450)
Then all the other .c files in the program can access them.
It is (almost) always a bad idea to put a variable definition in a header file.
A variable declaration , for example. extern byte numbers2[MAX_NUMBERS2];
tells the C compiler that the last related program has an array variable called numbers2
. If the linker does not get this definition (from somewhere else), it will throw an error because there is no room for the selected variable.
Definition of a variable (not from outside), for example. byte numbers2[MAX_NUMBERS2];
effectively tells the C compiler that there is an array variable called numbers2
and it must allocate a place here in the resulting object code from this source file, and this will be used to store the value of the variable in the final linked program,
The space for numbers2
not allocated by the C compiler when it sees the declaration (preceded by extern
), it is allocated when it sees the actual definition (without extern
).
Thus, if you put the actual definition of any variable in the header file and include it in several source code (.c) files, the C compiler will allocate space for the variable more than once. Then the linker will throw an error (usually multiple definitions with the same name).
There is a more subtle problem. If during the first development of the program the header file includes only one source file, then the program will be correctly compiled and compiled. Then, later, if the second source file contains a header (maybe someone just split the source file into two files), the linker will throw a "multiple definitions" error. This can be very confusing because the program was used to compile and link, and obviously nothing has changed.
Summary
Never allocate space for a variable by placing the definition in a header file. Place variable declarations in header files only.