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. Pointer to structure

Pointer to structure

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studiotutorial
16 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.
  • C Christian Graus

    What's the error message ? Yes, any type you can have as a pointer before it's declared, but it needs to be declared before you *use* the pointer. The point ( no pun intended ) is that the compiler can allocate space for a pointer before knowing how big the object is, but it can't access the object before it knows about it.

    Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

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

    I guess your "The point ( no pun intended ) is that " is meant "The point ( no pun intended ) is NOT that ". The declarations are in headers, far before the actual references. Other fields of the same structures can be referenced.

    C 1 Reply Last reply
    0
    • M Mark Salsbery

      Can you post code causing "very strange syntactical error messages " and maybe the struct definitions including the relevent circular reference? Mark

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

      No, I can't. It's too large and depending on too many components. One of the errors is H:\RawProc\TIFFProcessing.cpp(856) : error C2059: syntax error : '(' but this is on it's own useless. Some of the error messages are simply crazy (not fitting to the actual situation). If I can't find a solution, I will create an abstract example and post that.

      J P 2 Replies Last reply
      0
      • V Vancouver

        No, I can't. It's too large and depending on too many components. One of the errors is H:\RawProc\TIFFProcessing.cpp(856) : error C2059: syntax error : '(' but this is on it's own useless. Some of the error messages are simply crazy (not fitting to the actual situation). If I can't find a solution, I will create an abstract example and post that.

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #6

        Something else is likely wrong - the location of that error (line 856) leads me to believe something else is going on here.    You may have to post all of the related code, or at least provide a way to get to it.    Edit - or at least lines 850-560...!    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

        1 Reply Last reply
        0
        • V Vancouver

          I guess your "The point ( no pun intended ) is that " is meant "The point ( no pun intended ) is NOT that ". The declarations are in headers, far before the actual references. Other fields of the same structures can be referenced.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #7

          No, I meant what I said. The compiler can allocate a pointer before knowing what it's pointing to, but it can't use an object it knows nothing about.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          V 1 Reply Last reply
          0
          • C Christian Graus

            No, I meant what I said. The compiler can allocate a pointer before knowing what it's pointing to, but it can't use an object it knows nothing about.

            Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

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

            OK, I understand how you meant "the point". That's all trivial, as a pointer is always four bytes long, at least with VC6. As I indicated in my original post, all declarations are ahead.

            C 1 Reply Last reply
            0
            • V Vancouver

              OK, I understand how you meant "the point". That's all trivial, as a pointer is always four bytes long, at least with VC6. As I indicated in my original post, all declarations are ahead.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #9

              Vancouver wrote:

              That's all trivial, as a pointer is always four bytes long, at least with VC6.

              Yeah, that was my point.

              Vancouver wrote:

              As I indicated in my original post, all declarations are ahead.

              OK, then you have a different problem, which we can't help you with, without seeing the code.

              Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

              1 Reply Last reply
              0
              • V Vancouver

                No, I can't. It's too large and depending on too many components. One of the errors is H:\RawProc\TIFFProcessing.cpp(856) : error C2059: syntax error : '(' but this is on it's own useless. Some of the error messages are simply crazy (not fitting to the actual situation). If I can't find a solution, I will create an abstract example and post that.

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #10

                Vancouver wrote:

                H:\RawProc\TIFFProcessing.cpp(856) : error C2059: syntax error : '('

                It seems to be syntaxical one. Post some relevent code.

                Prasad Notifier using ATL | Operator new[],delete[][^]

                1 Reply Last reply
                0
                • V Vancouver

                  I am using VC++ 6.0 The Visual Studio documentation states unequivocally: Declarations of pointers to structures and typedefs for structure types can use the structure tag before the structure type is defined Then A member cannot be declared to have the type of the structure in which it appears. **However, a member can be declared as a pointer to the structure type in which it appears as long as the structure type has a tag. This allows you to create linked lists of structures** I have two structures containing pointers mutually to each other, one of them containing a chaining pointer to itself as well. I receive very strange syntactical error messages in the references to these pointers, for example referring to some left bracket, "(", (not present in the reference) and alike. I tried with an incomplete definition, like struct anystructure; before the structure using the other, but it did not help. The error messages slightly change, but that's it. Is this a known problem?

                  V Offline
                  V Offline
                  Vancouver
                  wrote on last edited by
                  #11

                  I created a simple example: void main() { struct SampleStr2 { char Anything; SampleStr2 *pNextStr; SampleStr1 *pSStr1; }; struct SampleStr1 { char Anychar; SampleStr2 *pSStr2; }; return; }; The error report is error C2143: syntax error : missing ';' before '*' error C2501: 'SampleStr1' : missing storage-class or type specifiers error C2501: 'pSStr1' : missing storage-class or type specifiers

                  J P 2 Replies Last reply
                  0
                  • V Vancouver

                    I created a simple example: void main() { struct SampleStr2 { char Anything; SampleStr2 *pNextStr; SampleStr1 *pSStr1; }; struct SampleStr1 { char Anychar; SampleStr2 *pSStr2; }; return; }; The error report is error C2143: syntax error : missing ';' before '*' error C2501: 'SampleStr1' : missing storage-class or type specifiers error C2501: 'pSStr1' : missing storage-class or type specifiers

                    J Offline
                    J Offline
                    Joe Woodbury
                    wrote on last edited by
                    #12

                    void main()
                    {
                    struct SampleStr1; // add this before the declaration of SampleStr2
                    struct SampleStr2
                    {
                    char Anything;
                    SampleStr2 *pNextStr;
                    SampleStr1 *pSStr1;
                    };

                    struct SampleStr1
                    {
                    char Anychar;
                    SampleStr2 *pSStr2;
                    };

                    return;
                    };

                    Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

                    V 1 Reply Last reply
                    0
                    • V Vancouver

                      I created a simple example: void main() { struct SampleStr2 { char Anything; SampleStr2 *pNextStr; SampleStr1 *pSStr1; }; struct SampleStr1 { char Anychar; SampleStr2 *pSStr2; }; return; }; The error report is error C2143: syntax error : missing ';' before '*' error C2501: 'SampleStr1' : missing storage-class or type specifiers error C2501: 'pSStr1' : missing storage-class or type specifiers

                      P Offline
                      P Offline
                      prasad_som
                      wrote on last edited by
                      #13

                      To add to Joe, This proves, its always better to provide problem code snippet.

                      Prasad Notifier using ATL | Operator new[],delete[][^]

                      1 Reply Last reply
                      0
                      • J Joe Woodbury

                        void main()
                        {
                        struct SampleStr1; // add this before the declaration of SampleStr2
                        struct SampleStr2
                        {
                        char Anything;
                        SampleStr2 *pNextStr;
                        SampleStr1 *pSStr1;
                        };

                        struct SampleStr1
                        {
                        char Anychar;
                        SampleStr2 *pSStr2;
                        };

                        return;
                        };

                        Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

                        V Offline
                        V Offline
                        Vancouver
                        wrote on last edited by
                        #14

                        I DID do it so, as I wrote it in the original post (my addition, that this did not correct the error was wrong). My main point was and is, that this contradicts the MS VC++ 6.0 documentation.

                        D 1 Reply Last reply
                        0
                        • V Vancouver

                          I DID do it so, as I wrote it in the original post (my addition, that this did not correct the error was wrong). My main point was and is, that this contradicts the MS VC++ 6.0 documentation.

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

                          So what's the point of your post then? If you need help with a problem, a solution has been provided. If you're just wanting to rant about MS's documentation, take a number. It's a known fact that you can't rely 100% upon MSDN documentation. While errors are rare, they do occur and thus you should be prepared to make corrections.


                          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                          "Judge not by the eye but by the heart." - Native American Proverb

                          V 1 Reply Last reply
                          0
                          • D David Crow

                            So what's the point of your post then? If you need help with a problem, a solution has been provided. If you're just wanting to rant about MS's documentation, take a number. It's a known fact that you can't rely 100% upon MSDN documentation. While errors are rare, they do occur and thus you should be prepared to make corrections.


                            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                            "Judge not by the eye but by the heart." - Native American Proverb

                            V Offline
                            V Offline
                            Vancouver
                            wrote on last edited by
                            #16

                            The docu of VC++6.0 is miserable, but that's not the same as factually erroneous. I haven't got used to the idea of fighting against factual errors in the documentation. However, in fairness I have to say, that this is not an error in the docu. After re-reading the documentation, I realized it: it states only that the definition does not have to be prior the pointer, but it says nothing about the declaration.

                            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