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 C2059

error C2059

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comlinuxdata-structures
31 Posts 7 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.
  • _ Offline
    _ Offline
    _Flaviu
    wrote on last edited by
    #1

    I am struggling from some time to an error:

    error C2059: syntax error : ')'

    I have somewhere in the old code:

    #define list_entry(ptr, type, member) \
    ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) // <-- here is the error ...

    I have tried this solution, without success: c - list_entry in Linux - Stack Overflow[^] How can I get rid of this error ? I am trying to integrate this code in an MFC project, and the code from above is from C code (for linux I guess)

    CPalliniC D M S 4 Replies Last reply
    0
    • _ _Flaviu

      I am struggling from some time to an error:

      error C2059: syntax error : ')'

      I have somewhere in the old code:

      #define list_entry(ptr, type, member) \
      ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) // <-- here is the error ...

      I have tried this solution, without success: c - list_entry in Linux - Stack Overflow[^] How can I get rid of this error ? I am trying to integrate this code in an MFC project, and the code from above is from C code (for linux I guess)

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Please show us the actual line of code where the error occurs.

      In testa che avete, signor di Ceprano?

      _ 1 Reply Last reply
      0
      • _ _Flaviu

        I am struggling from some time to an error:

        error C2059: syntax error : ')'

        I have somewhere in the old code:

        #define list_entry(ptr, type, member) \
        ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) // <-- here is the error ...

        I have tried this solution, without success: c - list_entry in Linux - Stack Overflow[^] How can I get rid of this error ? I am trying to integrate this code in an MFC project, and the code from above is from C code (for linux I guess)

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Syntactically that directive looks fine. Have you examined the preprocessor output (/P) to see what that directive looks like once expanded?

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

        _ 1 Reply Last reply
        0
        • CPalliniC CPallini

          Please show us the actual line of code where the error occurs.

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          const int nTest = list_next_entry(0, 0); // <-- error C2059: syntax error : ')'

          where list_next_entry is

          #define list_next_entry(pos, member) list_entry(0, 0, 0)

          and list_entry is defined in the first post. P.S. Of course, 0 values are for testing purpose only.

          L CPalliniC 2 Replies Last reply
          0
          • D David Crow

            Syntactically that directive looks fine. Have you examined the preprocessor output (/P) to see what that directive looks like once expanded?

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            _ Offline
            _ Offline
            _Flaviu
            wrote on last edited by
            #5

            There I have:

            _WINDOWS;NDEBUG;%(PreprocessorDefinitions)

            D 1 Reply Last reply
            0
            • _ _Flaviu

              There I have:

              _WINDOWS;NDEBUG;%(PreprocessorDefinitions)

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              This is the content of your .I file? :confused:

              "One man's wage rise is another man's price increase." - Harold Wilson

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

              1 Reply Last reply
              0
              • _ _Flaviu

                const int nTest = list_next_entry(0, 0); // <-- error C2059: syntax error : ')'

                where list_next_entry is

                #define list_next_entry(pos, member) list_entry(0, 0, 0)

                and list_entry is defined in the first post. P.S. Of course, 0 values are for testing purpose only.

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

                A good alternative is to not use #define directives in this way, as they only serve to confuse.

                _ 1 Reply Last reply
                0
                • _ _Flaviu

                  const int nTest = list_next_entry(0, 0); // <-- error C2059: syntax error : ')'

                  where list_next_entry is

                  #define list_next_entry(pos, member) list_entry(0, 0, 0)

                  and list_entry is defined in the first post. P.S. Of course, 0 values are for testing purpose only.

                  CPalliniC Offline
                  CPalliniC Offline
                  CPallini
                  wrote on last edited by
                  #8

                  Quote:

                  P.S. Of course, 0 values are for testing purpose only.

                  However they are bad arguments for a (very likely) legitimate macro. If you get the error with such arguments, then we cannot blame the compiler. On the other hand, if you're getting the same error with proper arguments then post such code here.

                  In testa che avete, signor di Ceprano?

                  _ 1 Reply Last reply
                  0
                  • _ _Flaviu

                    I am struggling from some time to an error:

                    error C2059: syntax error : ')'

                    I have somewhere in the old code:

                    #define list_entry(ptr, type, member) \
                    ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) // <-- here is the error ...

                    I have tried this solution, without success: c - list_entry in Linux - Stack Overflow[^] How can I get rid of this error ? I am trying to integrate this code in an MFC project, and the code from above is from C code (for linux I guess)

                    M Offline
                    M Offline
                    mo1492
                    wrote on last edited by
                    #9

                    This is a combination of all of the above responses. I have compiled this in mfc and it works. struct data { int something; }; struct container { int something_before; struct data data_item; int something_after; }; #define list_entry(ptr, type, member) \ ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) // <-- here is the error ... struct data *data_ptr; struct container *cont_ptr = list_entry(data_ptr, struct container, data_item); // This is the code you say is not compiling. #define list_next_entry(pos, member) list_entry(0, 0, 0) // This error is caused by the above line because list_entry(0,0,0) '0' is not a valid data type. const int nTest = list_next_entry(0, 0); // <-- error C2059: syntax error : ')' // If you do this instead... #define list_next_entry(pos, member) list_entry(data_ptr, struct container, data_item) // You will get a new error you will have to resolve in some way. // error C2440: 'initializing' : cannot convert from 'container *' to 'const int' // 1> There is no context in which this conversion is possible // The compiler can't convert a pointer to an int. // Don't know what you are trying to do. const int nTest = list_next_entry(0, 0);

                    _ 2 Replies Last reply
                    0
                    • L Lost User

                      A good alternative is to not use #define directives in this way, as they only serve to confuse.

                      _ Offline
                      _ Offline
                      _Flaviu
                      wrote on last edited by
                      #10

                      This is legacy code, is not written by me.

                      L 1 Reply Last reply
                      0
                      • CPalliniC CPallini

                        Quote:

                        P.S. Of course, 0 values are for testing purpose only.

                        However they are bad arguments for a (very likely) legitimate macro. If you get the error with such arguments, then we cannot blame the compiler. On the other hand, if you're getting the same error with proper arguments then post such code here.

                        _ Offline
                        _ Offline
                        _Flaviu
                        wrote on last edited by
                        #11

                        With 0 or original argumtents value, the error is the same.

                        CPalliniC 1 Reply Last reply
                        0
                        • _ _Flaviu

                          This is legacy code, is not written by me.

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

                          Then I would suggest you search out every usage of those defines and turn them into real code.

                          1 Reply Last reply
                          0
                          • _ _Flaviu

                            With 0 or original argumtents value, the error is the same.

                            CPalliniC Offline
                            CPalliniC Offline
                            CPallini
                            wrote on last edited by
                            #13

                            But I can't help on 0, because the compiler is absolutely right complaining.

                            In testa che avete, signor di Ceprano?

                            1 Reply Last reply
                            0
                            • M mo1492

                              This is a combination of all of the above responses. I have compiled this in mfc and it works. struct data { int something; }; struct container { int something_before; struct data data_item; int something_after; }; #define list_entry(ptr, type, member) \ ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) // <-- here is the error ... struct data *data_ptr; struct container *cont_ptr = list_entry(data_ptr, struct container, data_item); // This is the code you say is not compiling. #define list_next_entry(pos, member) list_entry(0, 0, 0) // This error is caused by the above line because list_entry(0,0,0) '0' is not a valid data type. const int nTest = list_next_entry(0, 0); // <-- error C2059: syntax error : ')' // If you do this instead... #define list_next_entry(pos, member) list_entry(data_ptr, struct container, data_item) // You will get a new error you will have to resolve in some way. // error C2440: 'initializing' : cannot convert from 'container *' to 'const int' // 1> There is no context in which this conversion is possible // The compiler can't convert a pointer to an int. // Don't know what you are trying to do. const int nTest = list_next_entry(0, 0);

                              _ Offline
                              _ Offline
                              _Flaviu
                              wrote on last edited by
                              #14

                              I am just trying to integrate a C old code into MFC project. I will try to do what you said, and give you a feedback.

                              1 Reply Last reply
                              0
                              • M mo1492

                                This is a combination of all of the above responses. I have compiled this in mfc and it works. struct data { int something; }; struct container { int something_before; struct data data_item; int something_after; }; #define list_entry(ptr, type, member) \ ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member))) // <-- here is the error ... struct data *data_ptr; struct container *cont_ptr = list_entry(data_ptr, struct container, data_item); // This is the code you say is not compiling. #define list_next_entry(pos, member) list_entry(0, 0, 0) // This error is caused by the above line because list_entry(0,0,0) '0' is not a valid data type. const int nTest = list_next_entry(0, 0); // <-- error C2059: syntax error : ')' // If you do this instead... #define list_next_entry(pos, member) list_entry(data_ptr, struct container, data_item) // You will get a new error you will have to resolve in some way. // error C2440: 'initializing' : cannot convert from 'container *' to 'const int' // 1> There is no context in which this conversion is possible // The compiler can't convert a pointer to an int. // Don't know what you are trying to do. const int nTest = list_next_entry(0, 0);

                                _ Offline
                                _ Offline
                                _Flaviu
                                wrote on last edited by
                                #15

                                The original code is just like that:

                                #define list_next_entry(pos, member) list_entry((pos)->member.next, typeof(*(pos)), member)

                                but the errors is little more then:

                                error C2100: illegal indirection
                                error C2059: syntax error : ')'
                                error C2059: syntax error : 'bad suffix on number'
                                error C3861: 'typeof': identifier not found

                                all of them is in the same line ...

                                S 1 Reply Last reply
                                0
                                • _ _Flaviu

                                  The original code is just like that:

                                  #define list_next_entry(pos, member) list_entry((pos)->member.next, typeof(*(pos)), member)

                                  but the errors is little more then:

                                  error C2100: illegal indirection
                                  error C2059: syntax error : ')'
                                  error C2059: syntax error : 'bad suffix on number'
                                  error C3861: 'typeof': identifier not found

                                  all of them is in the same line ...

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

                                  You can't use -> or * on a value of 0! That causes the compiler errors. Try any non-null value, and at least these compiler errors should go away. Moreover, typeof is not standard C/C++. There are implementations for that in the GCC extension for C, or in the BOOST library. You may need to find the correct BOOST library and include that in your project to make this code work.

                                  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)

                                  _ 3 Replies Last reply
                                  0
                                  • S Stefan_Lang

                                    You can't use -> or * on a value of 0! That causes the compiler errors. Try any non-null value, and at least these compiler errors should go away. Moreover, typeof is not standard C/C++. There are implementations for that in the GCC extension for C, or in the BOOST library. You may need to find the correct BOOST library and include that in your project to make this code work.

                                    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)

                                    _ Offline
                                    _ Offline
                                    _Flaviu
                                    wrote on last edited by
                                    #17

                                    Should I understand that pos has 0 value ? And what I could use instead of

                                    typeof

                                    without using BOOST ?

                                    1 Reply Last reply
                                    0
                                    • S Stefan_Lang

                                      You can't use -> or * on a value of 0! That causes the compiler errors. Try any non-null value, and at least these compiler errors should go away. Moreover, typeof is not standard C/C++. There are implementations for that in the GCC extension for C, or in the BOOST library. You may need to find the correct BOOST library and include that in your project to make this code work.

                                      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)

                                      _ Offline
                                      _ Offline
                                      _Flaviu
                                      wrote on last edited by
                                      #18

                                      This is the original code:

                                      #define list_next_entry(pos, member) \
                                      list_entry((pos)->member.next, typeof(*(pos)), member)

                                      1 Reply Last reply
                                      0
                                      • S Stefan_Lang

                                        You can't use -> or * on a value of 0! That causes the compiler errors. Try any non-null value, and at least these compiler errors should go away. Moreover, typeof is not standard C/C++. There are implementations for that in the GCC extension for C, or in the BOOST library. You may need to find the correct BOOST library and include that in your project to make this code work.

                                        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)

                                        _ Offline
                                        _ Offline
                                        _Flaviu
                                        wrote on last edited by
                                        #19

                                        So, as a conclusion, the code is:

                                        const int nTest = list\_next\_entry(0, 0);
                                        

                                        where list_next_entry is defined:

                                        #define list_next_entry(pos, member) \
                                        list_entry((pos)->member.next, typeof(*(pos)), member)

                                        and list_entry is defined as:

                                        #define list_entry(ptr, type, member) \
                                        ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member)))

                                        and for this code I get:

                                        error C2100: illegal indirection
                                        error C2059: syntax error : ')'
                                        error C2059: syntax error : 'bad suffix on number'
                                        error C3861: 'typeof': identifier not found

                                        at line "const int nTest = list_next_entry(0, 0);" I cannot get rid of these errors ... :(

                                        L 1 Reply Last reply
                                        0
                                        • _ _Flaviu

                                          So, as a conclusion, the code is:

                                          const int nTest = list\_next\_entry(0, 0);
                                          

                                          where list_next_entry is defined:

                                          #define list_next_entry(pos, member) \
                                          list_entry((pos)->member.next, typeof(*(pos)), member)

                                          and list_entry is defined as:

                                          #define list_entry(ptr, type, member) \
                                          ((type *)((char *)(ptr)-(size_t)(&((type *)0)->member)))

                                          and for this code I get:

                                          error C2100: illegal indirection
                                          error C2059: syntax error : ')'
                                          error C2059: syntax error : 'bad suffix on number'
                                          error C3861: 'typeof': identifier not found

                                          at line "const int nTest = list_next_entry(0, 0);" I cannot get rid of these errors ... :(

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

                                          _Flaviu wrote:

                                          I cannot get rid of these errors

                                          And you will not get rid of them as long as you keep using 0 as the parameters to the list_next_entry call. The define uses specific C/C++ types that are not valid if replaced by 0. In the above case this code translates as follows:

                                          // your statement
                                          const int nTest = list_next_entry(0, 0);

                                          // converts to:
                                          list_entry((0)->0.next, typeof(*(0)), 0)

                                          which makes no sense at all.

                                          _ 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