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 identifier before string constant

error: expected identifier before string constant

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tools
13 Posts 5 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 Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    I hope I can explain this problem. I can make an instance of a class in my main()

    CLASS\_I2CIO   i2c\_ads1115(DEVICE\_I2C,ADDRESS\_ADS);
    

    no problema. But if I add same code as class variable - I need an access to the class form main() - I get the following error.

    class C_VNA {
    public:
    C_VNA();
    virtual ~C_VNA();

    C\_Utility utility;
    CLASS\_LCM1602 i2c;	// default constructor x,x,x,x);
    CIOCTLGPIO gpio;    // GPIo
    C\_IOCTL\_SPI spi;    // temporary not coded
    C\_DDS\_60 dds;       // frequency
    C\_AD8302\_Detector det;
    C\_ADS1115 ads;
    CLASS\_I2CIO   i2c\_ioctl;       // genric i2c using ioctl
    

    error here
    CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
    error here
    };

    Partial compiler output

    Compiler executable checksum: 606522cdd68a1ba2fd9e2930e9d38d0d
    In file included from ../src/MODULES/M_VNA/CVNA.cpp:8:0:
    ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected identifier before string constant
    #define DEVICE_I2C "dev/i2c-1"
    ^
    ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
    src/MODULES/M_VNA/subdir.mk:18: recipe for target 'src/MODULES/M_VNA/CVNA.o' failed
    CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
    ^
    ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected ‘,’ or ‘...’ before string constant
    #define DEVICE_I2C "dev/i2c-1"
    ^
    ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
    CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
    ^
    make: *** [src/MODULES/M_VNA/CVNA.o] Error 1

    There is nothing special about #defines

    // devices
    #define DEVICE_SPI "dev/spidev0.0"
    #define DEVICE_I2C "dev/i2c-1"

    // define i2c addresses
    #define ADDRESS_HITACHI 0x27
    #define ADDRESS_ADS 0x48

    The error "points " to #define which is redefined in this class - temporary for test purposes. I did look thru similar problems and they all indicate the #define is NOT the issue, however I am unable to figure this out and correct it. Any help would be appreciated. Cheers

    L K G S 4 Replies Last reply
    0
    • V Vaclav_

      I hope I can explain this problem. I can make an instance of a class in my main()

      CLASS\_I2CIO   i2c\_ads1115(DEVICE\_I2C,ADDRESS\_ADS);
      

      no problema. But if I add same code as class variable - I need an access to the class form main() - I get the following error.

      class C_VNA {
      public:
      C_VNA();
      virtual ~C_VNA();

      C\_Utility utility;
      CLASS\_LCM1602 i2c;	// default constructor x,x,x,x);
      CIOCTLGPIO gpio;    // GPIo
      C\_IOCTL\_SPI spi;    // temporary not coded
      C\_DDS\_60 dds;       // frequency
      C\_AD8302\_Detector det;
      C\_ADS1115 ads;
      CLASS\_I2CIO   i2c\_ioctl;       // genric i2c using ioctl
      

      error here
      CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
      error here
      };

      Partial compiler output

      Compiler executable checksum: 606522cdd68a1ba2fd9e2930e9d38d0d
      In file included from ../src/MODULES/M_VNA/CVNA.cpp:8:0:
      ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected identifier before string constant
      #define DEVICE_I2C "dev/i2c-1"
      ^
      ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
      src/MODULES/M_VNA/subdir.mk:18: recipe for target 'src/MODULES/M_VNA/CVNA.o' failed
      CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
      ^
      ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected ‘,’ or ‘...’ before string constant
      #define DEVICE_I2C "dev/i2c-1"
      ^
      ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
      CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
      ^
      make: *** [src/MODULES/M_VNA/CVNA.o] Error 1

      There is nothing special about #defines

      // devices
      #define DEVICE_SPI "dev/spidev0.0"
      #define DEVICE_I2C "dev/i2c-1"

      // define i2c addresses
      #define ADDRESS_HITACHI 0x27
      #define ADDRESS_ADS 0x48

      The error "points " to #define which is redefined in this class - temporary for test purposes. I did look thru similar problems and they all indicate the #define is NOT the issue, however I am unable to figure this out and correct it. Any help would be appreciated. Cheers

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

      Where is the definition of CLASS_I2CIO and its constructors?

      V 1 Reply Last reply
      0
      • L Lost User

        Where is the definition of CLASS_I2CIO and its constructors?

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

        Here is the part in question

        class CLASS_I2CIO {
        public:
        CLASS_I2CIO();
        CLASS_I2CIO(char Device, int Address);
        CLASS_I2CIO(int width, int length, int height)
        : m_width(width), m_length(length), m_height(height)
        {}

        CLASS\_I2CIO(char \*x1, int y1); // :
        

        this is the one which fails
        CLASS_I2CIO(char *x1, int y1, int Width, int Height);

        private:
        char *device;
        int address;
        int width, height;

        public:
        virtual ~CLASS_I2CIO();
        int FileDescriptor = 0;

        // class variables
        \_\_u8 reg;  /\* Device register to access \*/
        \_\_s32 res;
        char buffer\[10\]= { }; // clear buffer  - was not initialized
        
        L S 2 Replies Last reply
        0
        • V Vaclav_

          I hope I can explain this problem. I can make an instance of a class in my main()

          CLASS\_I2CIO   i2c\_ads1115(DEVICE\_I2C,ADDRESS\_ADS);
          

          no problema. But if I add same code as class variable - I need an access to the class form main() - I get the following error.

          class C_VNA {
          public:
          C_VNA();
          virtual ~C_VNA();

          C\_Utility utility;
          CLASS\_LCM1602 i2c;	// default constructor x,x,x,x);
          CIOCTLGPIO gpio;    // GPIo
          C\_IOCTL\_SPI spi;    // temporary not coded
          C\_DDS\_60 dds;       // frequency
          C\_AD8302\_Detector det;
          C\_ADS1115 ads;
          CLASS\_I2CIO   i2c\_ioctl;       // genric i2c using ioctl
          

          error here
          CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
          error here
          };

          Partial compiler output

          Compiler executable checksum: 606522cdd68a1ba2fd9e2930e9d38d0d
          In file included from ../src/MODULES/M_VNA/CVNA.cpp:8:0:
          ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected identifier before string constant
          #define DEVICE_I2C "dev/i2c-1"
          ^
          ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
          src/MODULES/M_VNA/subdir.mk:18: recipe for target 'src/MODULES/M_VNA/CVNA.o' failed
          CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
          ^
          ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected ‘,’ or ‘...’ before string constant
          #define DEVICE_I2C "dev/i2c-1"
          ^
          ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
          CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
          ^
          make: *** [src/MODULES/M_VNA/CVNA.o] Error 1

          There is nothing special about #defines

          // devices
          #define DEVICE_SPI "dev/spidev0.0"
          #define DEVICE_I2C "dev/i2c-1"

          // define i2c addresses
          #define ADDRESS_HITACHI 0x27
          #define ADDRESS_ADS 0x48

          The error "points " to #define which is redefined in this class - temporary for test purposes. I did look thru similar problems and they all indicate the #define is NOT the issue, however I am unable to figure this out and correct it. Any help would be appreciated. Cheers

          K Offline
          K Offline
          k5054
          wrote on last edited by
          #4

          Vaclav_ wrote:

          The error "points " to #define which is redefined in this class - temporary for test purposes.

          Are you doing something like this?

          #include "spi.h" // #defines DEVICE_SPI, etc

          #define DEVICE_SPI_"dev/spidev0.0" // Temporary define

          class C_VNA {
          // ...
          };

          That would mean that you're re-defining DEVICE_SPI, but normally your compiler should warn about redifines. Maybe you need #undef where you set up your temp defines. e.g.

          #ifdef DEVICE_SPI
          #define ORIG_DEVICE_SPI DEVICE_SPI
          #undef DEVICE_SPI
          #endif
          #define DEVICE_SPI "dev/spidev0.0"
          // your code here that uses the temporary DEVICE_SPI

          #ifdef ORIG_DEVICE_SPI
          #undef DEVICE_SPI
          #define DEVICE_SPI ORIG_DEVICE_SPI
          #undef ORIG_DEVICE_SPI
          #endif

          1 Reply Last reply
          0
          • V Vaclav_

            Here is the part in question

            class CLASS_I2CIO {
            public:
            CLASS_I2CIO();
            CLASS_I2CIO(char Device, int Address);
            CLASS_I2CIO(int width, int length, int height)
            : m_width(width), m_length(length), m_height(height)
            {}

            CLASS\_I2CIO(char \*x1, int y1); // :
            

            this is the one which fails
            CLASS_I2CIO(char *x1, int y1, int Width, int Height);

            private:
            char *device;
            int address;
            int width, height;

            public:
            virtual ~CLASS_I2CIO();
            int FileDescriptor = 0;

            // class variables
            \_\_u8 reg;  /\* Device register to access \*/
            \_\_s32 res;
            char buffer\[10\]= { }; // clear buffer  - was not initialized
            
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            That is incomplete, and will not even compile, so it is impossible to guess what else may be wrong. [edit] See Graham's answer below. [/edit]

            1 Reply Last reply
            0
            • V Vaclav_

              I hope I can explain this problem. I can make an instance of a class in my main()

              CLASS\_I2CIO   i2c\_ads1115(DEVICE\_I2C,ADDRESS\_ADS);
              

              no problema. But if I add same code as class variable - I need an access to the class form main() - I get the following error.

              class C_VNA {
              public:
              C_VNA();
              virtual ~C_VNA();

              C\_Utility utility;
              CLASS\_LCM1602 i2c;	// default constructor x,x,x,x);
              CIOCTLGPIO gpio;    // GPIo
              C\_IOCTL\_SPI spi;    // temporary not coded
              C\_DDS\_60 dds;       // frequency
              C\_AD8302\_Detector det;
              C\_ADS1115 ads;
              CLASS\_I2CIO   i2c\_ioctl;       // genric i2c using ioctl
              

              error here
              CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
              error here
              };

              Partial compiler output

              Compiler executable checksum: 606522cdd68a1ba2fd9e2930e9d38d0d
              In file included from ../src/MODULES/M_VNA/CVNA.cpp:8:0:
              ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected identifier before string constant
              #define DEVICE_I2C "dev/i2c-1"
              ^
              ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
              src/MODULES/M_VNA/subdir.mk:18: recipe for target 'src/MODULES/M_VNA/CVNA.o' failed
              CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
              ^
              ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected ‘,’ or ‘...’ before string constant
              #define DEVICE_I2C "dev/i2c-1"
              ^
              ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
              CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
              ^
              make: *** [src/MODULES/M_VNA/CVNA.o] Error 1

              There is nothing special about #defines

              // devices
              #define DEVICE_SPI "dev/spidev0.0"
              #define DEVICE_I2C "dev/i2c-1"

              // define i2c addresses
              #define ADDRESS_HITACHI 0x27
              #define ADDRESS_ADS 0x48

              The error "points " to #define which is redefined in this class - temporary for test purposes. I did look thru similar problems and they all indicate the #define is NOT the issue, however I am unable to figure this out and correct it. Any help would be appreciated. Cheers

              G Offline
              G Offline
              Graham Breach
              wrote on last edited by
              #6

              Inside a function, this declares a variable called i2c_ads1115 with type CLASS_I2CIO and calls the constructor with the two values DEVICE_I2C and ADDRESS_ADS:

              CLASS_I2CIO i2c_ads1115(DEVICE_I2C,ADDRESS_ADS);

              Inside a class definition it declares a member function called i2c_ads1115 that returns a CLASS_I2CIO type and takes two arguments, which is where the compiler is having problems. Instead of DEVICE_I2C being a type, you have a #defined string. To get i2c_ads1115 as a member variable, declare it the same way as the i2c_ioctl member variable, then construct it with arguments in the initialization list of the C_VNA class.

              V 1 Reply Last reply
              0
              • G Graham Breach

                Inside a function, this declares a variable called i2c_ads1115 with type CLASS_I2CIO and calls the constructor with the two values DEVICE_I2C and ADDRESS_ADS:

                CLASS_I2CIO i2c_ads1115(DEVICE_I2C,ADDRESS_ADS);

                Inside a class definition it declares a member function called i2c_ads1115 that returns a CLASS_I2CIO type and takes two arguments, which is where the compiler is having problems. Instead of DEVICE_I2C being a type, you have a #defined string. To get i2c_ads1115 as a member variable, declare it the same way as the i2c_ioctl member variable, then construct it with arguments in the initialization list of the C_VNA class.

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

                Thanks, I'll give it a go. One more question. Why I have no issue with using same syntax making an instance of the class in main ()? Stupid question - could I just change the #define to "include" type ?

                G 1 Reply Last reply
                0
                • V Vaclav_

                  Thanks, I'll give it a go. One more question. Why I have no issue with using same syntax making an instance of the class in main ()? Stupid question - could I just change the #define to "include" type ?

                  G Offline
                  G Offline
                  Graham Breach
                  wrote on last edited by
                  #8

                  I can't say why that syntax defines a variable using a constructor in one place and declares a member function in another - you would have to ask the people who designed C++ that. Making the #define include the type would probably give you a different error message, but it would still be attempting to declare a member function.

                  1 Reply Last reply
                  0
                  • V Vaclav_

                    I hope I can explain this problem. I can make an instance of a class in my main()

                    CLASS\_I2CIO   i2c\_ads1115(DEVICE\_I2C,ADDRESS\_ADS);
                    

                    no problema. But if I add same code as class variable - I need an access to the class form main() - I get the following error.

                    class C_VNA {
                    public:
                    C_VNA();
                    virtual ~C_VNA();

                    C\_Utility utility;
                    CLASS\_LCM1602 i2c;	// default constructor x,x,x,x);
                    CIOCTLGPIO gpio;    // GPIo
                    C\_IOCTL\_SPI spi;    // temporary not coded
                    C\_DDS\_60 dds;       // frequency
                    C\_AD8302\_Detector det;
                    C\_ADS1115 ads;
                    CLASS\_I2CIO   i2c\_ioctl;       // genric i2c using ioctl
                    

                    error here
                    CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
                    error here
                    };

                    Partial compiler output

                    Compiler executable checksum: 606522cdd68a1ba2fd9e2930e9d38d0d
                    In file included from ../src/MODULES/M_VNA/CVNA.cpp:8:0:
                    ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected identifier before string constant
                    #define DEVICE_I2C "dev/i2c-1"
                    ^
                    ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
                    src/MODULES/M_VNA/subdir.mk:18: recipe for target 'src/MODULES/M_VNA/CVNA.o' failed
                    CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
                    ^
                    ../src/MODULES/M_VNA/CVNA.h:28:20: error: expected ‘,’ or ‘...’ before string constant
                    #define DEVICE_I2C "dev/i2c-1"
                    ^
                    ../src/MODULES/M_VNA/CVNA.h:60:36: note: in expansion of macro ‘DEVICE_I2C’
                    CLASS_I2CIO i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS);
                    ^
                    make: *** [src/MODULES/M_VNA/CVNA.o] Error 1

                    There is nothing special about #defines

                    // devices
                    #define DEVICE_SPI "dev/spidev0.0"
                    #define DEVICE_I2C "dev/i2c-1"

                    // define i2c addresses
                    #define ADDRESS_HITACHI 0x27
                    #define ADDRESS_ADS 0x48

                    The error "points " to #define which is redefined in this class - temporary for test purposes. I did look thru similar problems and they all indicate the #define is NOT the issue, however I am unable to figure this out and correct it. Any help would be appreciated. Cheers

                    S Offline
                    S Offline
                    Stefan_Lang
                    wrote on last edited by
                    #9

                    The compiler expects a function signature, but the function arguments you specified are missing a type. Try somthing like this

                    CLASS_I2CIO i2c_ads1115_test(const char* DEVICE_I2C, int ADDRESS_ADS);

                    (not sure what type the second argument is supposed to be)

                    GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                    V 1 Reply Last reply
                    0
                    • V Vaclav_

                      Here is the part in question

                      class CLASS_I2CIO {
                      public:
                      CLASS_I2CIO();
                      CLASS_I2CIO(char Device, int Address);
                      CLASS_I2CIO(int width, int length, int height)
                      : m_width(width), m_length(length), m_height(height)
                      {}

                      CLASS\_I2CIO(char \*x1, int y1); // :
                      

                      this is the one which fails
                      CLASS_I2CIO(char *x1, int y1, int Width, int Height);

                      private:
                      char *device;
                      int address;
                      int width, height;

                      public:
                      virtual ~CLASS_I2CIO();
                      int FileDescriptor = 0;

                      // class variables
                      \_\_u8 reg;  /\* Device register to access \*/
                      \_\_s32 res;
                      char buffer\[10\]= { }; // clear buffer  - was not initialized
                      
                      S Offline
                      S Offline
                      Stefan_Lang
                      wrote on last edited by
                      #10

                      CLASS_I2CIO(char Device, int Address);

                      Surely you mean char* Device, not char Device? If the erroneous line is supposed to be an initialization of a variable calling this constructor, then that is not going to work: you can not initialize a member variable right inside the class declaration, unless it is static. Instead you have to do the initialization inside the constructor, like this:

                      class C_VNA {
                      C_VNA();
                      ...
                      CLASS_I2CIO i2c_ads1115_test; // just declaring the type of the member variable here
                      };
                      ...
                      // constructors
                      // initialize the class members here (only needed when not using default constructor)
                      C_VNA::C_VNA()
                      : i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS)
                      {
                      // more initialization code
                      }

                      [edit2]reintroduced tags [/edit]

                      L 1 Reply Last reply
                      0
                      • S Stefan_Lang

                        CLASS_I2CIO(char Device, int Address);

                        Surely you mean char* Device, not char Device? If the erroneous line is supposed to be an initialization of a variable calling this constructor, then that is not going to work: you can not initialize a member variable right inside the class declaration, unless it is static. Instead you have to do the initialization inside the constructor, like this:

                        class C_VNA {
                        C_VNA();
                        ...
                        CLASS_I2CIO i2c_ads1115_test; // just declaring the type of the member variable here
                        };
                        ...
                        // constructors
                        // initialize the class members here (only needed when not using default constructor)
                        C_VNA::C_VNA()
                        : i2c_ads1115_test(DEVICE_I2C,ADDRESS_ADS)
                        {
                        // more initialization code
                        }

                        [edit2]reintroduced tags [/edit]

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

                        Stefan_Lang wrote:

                        had to remove tags - for some reason they are not working!?

                        Look at the checkboxes below the edit window. Do you have "Treat my content as plain text, not as HTML" set?

                        S 1 Reply Last reply
                        0
                        • L Lost User

                          Stefan_Lang wrote:

                          had to remove tags - for some reason they are not working!?

                          Look at the checkboxes below the edit window. Do you have "Treat my content as plain text, not as HTML" set?

                          S Offline
                          S Offline
                          Stefan_Lang
                          wrote on last edited by
                          #12

                          Thanks, that was indeed the problem. No idea why it was checked - I almost always use tags. :confused: GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                          1 Reply Last reply
                          0
                          • S Stefan_Lang

                            The compiler expects a function signature, but the function arguments you specified are missing a type. Try somthing like this

                            CLASS_I2CIO i2c_ads1115_test(const char* DEVICE_I2C, int ADDRESS_ADS);

                            (not sure what type the second argument is supposed to be)

                            GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

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

                            Second argument function is an I2C device address = in this case A/D converter ADS1115.

                            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