Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error: expected unqualified-id before numeric constant

error: expected unqualified-id before numeric constant

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabasedebuggingquestionworkspace
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Vaclav_

    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

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    You have declared font_vga_8x8 as a variable which is a structure of type fbcon_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
    };

    1 Reply Last reply
    0
    • V Vaclav_

      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

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #3

      You are mixing the declaration syntax for structs and typedefs 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 use

      struct 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.

      1 Reply Last reply
      0
      • V Vaclav_

        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

        V Offline
        V Offline
        Vaclav_
        wrote on last edited by
        #4

        I do not want to sound as smart aleck , but came up with "problem" definition , not particularly solution before I went to sleep last night. You guys are terrific helpers, I really appreciate this forum staff. What a difference from others forum!

        1 Reply Last reply
        0
        • V Vaclav_

          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

          V Offline
          V Offline
          Vaclav_
          wrote on last edited by
          #5

          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
          };
          #endif

          There 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

          L 1 Reply Last reply
          0
          • V Vaclav_

            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
            };
            #endif

            There 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

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            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.

            V 2 Replies Last reply
            0
            • L Lost User

              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.

              V Offline
              V Offline
              Vaclav_
              wrote on last edited by
              #7

              Thanks. Good call, I tend to forget to disable unused source files! Back to drawing board.

              1 Reply Last reply
              0
              • L Lost User

                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.

                V Offline
                V Offline
                Vaclav_
                wrote on last edited by
                #8

                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.

                L 1 Reply Last reply
                0
                • V Vaclav_

                  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.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  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.

                  V 1 Reply Last reply
                  0
                  • L Lost User

                    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.

                    V Offline
                    V Offline
                    Vaclav_
                    wrote on last edited by
                    #10

                    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.

                    L 1 Reply Last reply
                    0
                    • V Vaclav_

                      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.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      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.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups