Pointer to structure
-
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
ThenA 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, likestruct 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? -
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
ThenA 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, likestruct 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?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
-
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
ThenA 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, likestruct 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?Can you post code causing "very strange syntactical error messages " and maybe the struct definitions including the relevent circular reference? Mark
-
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
-
Can you post code causing "very strange syntactical error messages " and maybe the struct definitions including the relevent circular reference? Mark
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. -
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.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 -
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.
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
-
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
-
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.
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
-
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.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[][^]
-
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
ThenA 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, likestruct 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?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 iserror C2143: syntax error : missing ';' before '*' error C2501: 'SampleStr1' : missing storage-class or type specifiers error C2501: 'pSStr1' : missing storage-class or type specifiers
-
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 iserror C2143: syntax error : missing ';' before '*' error C2501: 'SampleStr1' : missing storage-class or type specifiers error C2501: 'pSStr1' : missing storage-class or type specifiers
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
-
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 iserror C2143: syntax error : missing ';' before '*' error C2501: 'SampleStr1' : missing storage-class or type specifiers error C2501: 'pSStr1' : missing storage-class or type specifiers
To add to Joe, This proves, its always better to provide problem code snippet.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
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
-
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.
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
-
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
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.