error: expected unqualified-id before numeric constant
-
I need some help, again. I am posting only what I hope is relevant code, if not ask for clarification or ignore my request. Basically struct issue. The error is /media/os64/Eclipse/eclipse/Workspace/Eclipse_Oxygen_1A/VNA_2/src/MODULES/M_SPI/C_FB.h:63:20: error: expected unqualified-id before numeric constant #define VGA8x8_IDX 0 ^ and I have no idea why. Just guessing something to do with struct initialization, but why? The code is in header file which contains data to "build" ASCII characters in pixels to be output to TFT display. I did move all into a class but got same error on #define VGA8x8_IDX 0. Here is part of the "font" code
static unsigned char fontdata_8x8[FONTDATAMAX] = {
/\* 0 0x00 '^@' \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ /\* 1 0x01 '^A' \*/ 0x7e, /\* 01111110 \*/ 0x81, /\* 10000001 \*/ 0xa5, /\* 10100101 \*/ 0x81, /\* 10000001 \*/ 0xbd, /\* 10111101 \*/ 0x99, /\* 10011001 \*/ 0x81, /\* 10000001 \*/ 0x7e, /\* 01111110 \*/
Here is the failing #define #include "TEST_FONT.h" // local copy #define VGA8x8_IDX 0 #define DEBUG And the structs code
struct fbcon\_font\_desc { int index ; // idx; char \*name; int width, height; unsigned char \*data; // font data int pref; }font\_vga\_8x8; struct font\_vga\_8x8 { VGA8x8\_IDX, "VGA8x8", 8, 8, fontdata\_8x8, 0 };
AS always, help will be appreciated. Cheers
You have declared
font_vga_8x8
as a variable which is a structure of typefbcon_font_desc
. You then try to redeclare it as a new struct type, initialised with values rather than declarations. Your code should be:struct fbcon_font_desc {
int index ; // idx;
char *name;
int width, height;
unsigned char *data; // font data
int pref;
} font_vga_8x8 = // this is the name of the actual structure variable
{
VGA8x8_IDX,
"VGA8x8",
8,
8,
fontdata_8x8,
0
}; -
I need some help, again. I am posting only what I hope is relevant code, if not ask for clarification or ignore my request. Basically struct issue. The error is /media/os64/Eclipse/eclipse/Workspace/Eclipse_Oxygen_1A/VNA_2/src/MODULES/M_SPI/C_FB.h:63:20: error: expected unqualified-id before numeric constant #define VGA8x8_IDX 0 ^ and I have no idea why. Just guessing something to do with struct initialization, but why? The code is in header file which contains data to "build" ASCII characters in pixels to be output to TFT display. I did move all into a class but got same error on #define VGA8x8_IDX 0. Here is part of the "font" code
static unsigned char fontdata_8x8[FONTDATAMAX] = {
/\* 0 0x00 '^@' \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ /\* 1 0x01 '^A' \*/ 0x7e, /\* 01111110 \*/ 0x81, /\* 10000001 \*/ 0xa5, /\* 10100101 \*/ 0x81, /\* 10000001 \*/ 0xbd, /\* 10111101 \*/ 0x99, /\* 10011001 \*/ 0x81, /\* 10000001 \*/ 0x7e, /\* 01111110 \*/
Here is the failing #define #include "TEST_FONT.h" // local copy #define VGA8x8_IDX 0 #define DEBUG And the structs code
struct fbcon\_font\_desc { int index ; // idx; char \*name; int width, height; unsigned char \*data; // font data int pref; }font\_vga\_8x8; struct font\_vga\_8x8 { VGA8x8\_IDX, "VGA8x8", 8, 8, fontdata\_8x8, 0 };
AS always, help will be appreciated. Cheers
You are mixing the declaration syntax for
struct
s andtypedef
s and forgot to specify a variable name for the instance of your structure. See Struct declaration - cppreference.com[^], Typedef declaration - cppreference.com[^] and Struct and union initialization - cppreference.com[^]. Either usestruct fbcon_font_desc {
int index ; // idx;
char *name;
int width, height;
unsigned char *data; // font data
int pref;
};
// Type is struct fbcon_font_desc
struct fbcon_font_desc font_vga_8x8 = { /* init members here */ };or
typedef struct {
int index ; // idx;
char *name;
int width, height;
unsigned char *data; // font data
int pref;
} fbcon_font_desc;
// Type is fbcon_font_desc
fbcon_font_desc font_vga_8x8 = { /* init members here */ };or use the solution provided by Richard.
-
I need some help, again. I am posting only what I hope is relevant code, if not ask for clarification or ignore my request. Basically struct issue. The error is /media/os64/Eclipse/eclipse/Workspace/Eclipse_Oxygen_1A/VNA_2/src/MODULES/M_SPI/C_FB.h:63:20: error: expected unqualified-id before numeric constant #define VGA8x8_IDX 0 ^ and I have no idea why. Just guessing something to do with struct initialization, but why? The code is in header file which contains data to "build" ASCII characters in pixels to be output to TFT display. I did move all into a class but got same error on #define VGA8x8_IDX 0. Here is part of the "font" code
static unsigned char fontdata_8x8[FONTDATAMAX] = {
/\* 0 0x00 '^@' \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ /\* 1 0x01 '^A' \*/ 0x7e, /\* 01111110 \*/ 0x81, /\* 10000001 \*/ 0xa5, /\* 10100101 \*/ 0x81, /\* 10000001 \*/ 0xbd, /\* 10111101 \*/ 0x99, /\* 10011001 \*/ 0x81, /\* 10000001 \*/ 0x7e, /\* 01111110 \*/
Here is the failing #define #include "TEST_FONT.h" // local copy #define VGA8x8_IDX 0 #define DEBUG And the structs code
struct fbcon\_font\_desc { int index ; // idx; char \*name; int width, height; unsigned char \*data; // font data int pref; }font\_vga\_8x8; struct font\_vga\_8x8 { VGA8x8\_IDX, "VGA8x8", 8, 8, fontdata\_8x8, 0 };
AS always, help will be appreciated. Cheers
-
I need some help, again. I am posting only what I hope is relevant code, if not ask for clarification or ignore my request. Basically struct issue. The error is /media/os64/Eclipse/eclipse/Workspace/Eclipse_Oxygen_1A/VNA_2/src/MODULES/M_SPI/C_FB.h:63:20: error: expected unqualified-id before numeric constant #define VGA8x8_IDX 0 ^ and I have no idea why. Just guessing something to do with struct initialization, but why? The code is in header file which contains data to "build" ASCII characters in pixels to be output to TFT display. I did move all into a class but got same error on #define VGA8x8_IDX 0. Here is part of the "font" code
static unsigned char fontdata_8x8[FONTDATAMAX] = {
/\* 0 0x00 '^@' \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ 0x00, /\* 00000000 \*/ /\* 1 0x01 '^A' \*/ 0x7e, /\* 01111110 \*/ 0x81, /\* 10000001 \*/ 0xa5, /\* 10100101 \*/ 0x81, /\* 10000001 \*/ 0xbd, /\* 10111101 \*/ 0x99, /\* 10011001 \*/ 0x81, /\* 10000001 \*/ 0x7e, /\* 01111110 \*/
Here is the failing #define #include "TEST_FONT.h" // local copy #define VGA8x8_IDX 0 #define DEBUG And the structs code
struct fbcon\_font\_desc { int index ; // idx; char \*name; int width, height; unsigned char \*data; // font data int pref; }font\_vga\_8x8; struct font\_vga\_8x8 { VGA8x8\_IDX, "VGA8x8", 8, 8, fontdata\_8x8, 0 };
AS always, help will be appreciated. Cheers
I am back. Sorry. The solution worked, but now I am back with "multiple definitions". That is where I started before getting into the mess with "struct". I have the usual #ifndef #define #endif "scaffolding" at the header file and it is #include only once anyway. I did add another #ifndef #define #endif around the "struct" but it did not help. The "worst" part is - the compiler error does not really tell me where is the multiple definition in the "main()". Or maybe I really do not know how to interpret the error in main().
#ifndef DEFINITION_
#define DEFINITION_struct fbcon_font_desc {
int idx;
char *name;
int width, height;
unsigned char *data; // font data
int pref;
}font_vga_8x8 = // test comment
{
VGA8x8_IDX, // test comment
"VGA8x8",
8,
8,
fontdata_8x8,
0
};
#endifThere is part of the compiler output
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9)
COMPILER_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'VNA_2' '-shared-libgcc' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabihf/5/collect2 -plugin /usr/lib/gcc-cross/arm-linux-gnueabihf/5/liblto_plugin.so -plugin-opt=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/lto-wrapper -plugin-opt=-fresolution=/tmp/ccC7xvZK.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ --build-id --eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X --hash-style=gnu --as-needed -m armelf_linux_eabi -z relro -o VNA_2 /usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/../lib/crt1.o /usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/../lib/crti.o /usr/lib/gcc-cross/arm-linux-gnueabi -
I am back. Sorry. The solution worked, but now I am back with "multiple definitions". That is where I started before getting into the mess with "struct". I have the usual #ifndef #define #endif "scaffolding" at the header file and it is #include only once anyway. I did add another #ifndef #define #endif around the "struct" but it did not help. The "worst" part is - the compiler error does not really tell me where is the multiple definition in the "main()". Or maybe I really do not know how to interpret the error in main().
#ifndef DEFINITION_
#define DEFINITION_struct fbcon_font_desc {
int idx;
char *name;
int width, height;
unsigned char *data; // font data
int pref;
}font_vga_8x8 = // test comment
{
VGA8x8_IDX, // test comment
"VGA8x8",
8,
8,
fontdata_8x8,
0
};
#endifThere is part of the compiler output
Thread model: posix
gcc version 5.4.0 20160609 (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.9)
COMPILER_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'VNA_2' '-shared-libgcc' '-march=armv7-a' '-mfloat-abi=hard' '-mfpu=vfpv3-d16' '-mthumb' '-mtls-dialect=gnu'
/usr/lib/gcc-cross/arm-linux-gnueabihf/5/collect2 -plugin /usr/lib/gcc-cross/arm-linux-gnueabihf/5/liblto_plugin.so -plugin-opt=/usr/lib/gcc-cross/arm-linux-gnueabihf/5/lto-wrapper -plugin-opt=-fresolution=/tmp/ccC7xvZK.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/ --build-id --eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X --hash-style=gnu --as-needed -m armelf_linux_eabi -z relro -o VNA_2 /usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/../lib/crt1.o /usr/lib/gcc-cross/arm-linux-gnueabihf/5/../../../../arm-linux-gnueabihf/lib/../lib/crti.o /usr/lib/gcc-cross/arm-linux-gnueabi -
This is a linker error, not a compiler error. You have a definition of
font_vga_8x8
in more than one source module. So although that looks OK to the compiler, when you link the object modules together the linker gets confused. -
This is a linker error, not a compiler error. You have a definition of
font_vga_8x8
in more than one source module. So although that looks OK to the compiler, when you link the object modules together the linker gets confused.Well - I did try to cheat and renamed the offending variable. Still same error - multiple definitions. Then I recall something about initializing struct as globals or something to that matter. So I changed the struct to "static " and the error went away. Why? The #include file is global - not part of the class.
-
Well - I did try to cheat and renamed the offending variable. Still same error - multiple definitions. Then I recall something about initializing struct as globals or something to that matter. So I changed the struct to "static " and the error went away. Why? The #include file is global - not part of the class.
The problem is not specific to struct types, but any variable. If a variable has global scope, i.e. it is declared outside of any method, then it is externally defined by default. That means its name is known to the linker. If it is declared static then it is internal to the compilation unit that contains it, and its name will not be visible to the linker. So if the linker encounters multiple variables with the same name it cannot decide how to link them correctly.
-
The problem is not specific to struct types, but any variable. If a variable has global scope, i.e. it is declared outside of any method, then it is externally defined by default. That means its name is known to the linker. If it is declared static then it is internal to the compilation unit that contains it, and its name will not be visible to the linker. So if the linker encounters multiple variables with the same name it cannot decide how to link them correctly.
Ok, so if I put the struct declaration / definition as class variable it should work without being declared as static , right? Would that defeat the purpose of #include in general? This "font definitions" came from other application, not my original code.
-
Ok, so if I put the struct declaration / definition as class variable it should work without being declared as static , right? Would that defeat the purpose of #include in general? This "font definitions" came from other application, not my original code.
Sorry those three statements don't make much sense. The general way of handling situations like yours is to have the definition of the struct in a header file that multiple source modules can then include. Each source module would then declare an instance of the struct in what ever location they required, but not as a global. Having said that, there may be cases where declaring such a variable as global is the right thing to do, as its contents are shared between different modules. Only you (the application designer) can decide which is the right option.