Posted: 31 Aug 2010, 11:33
The AI part of the re-volt source code seems to be the most complex. But there is one part of AINode code in the source that really confuses me. Can someone with C knowledge clarify this?
Suppose there is a structure like this. As you can see, the 4 members of the structure are pointers to the same type as the struct itself.
Suppose you create a variable like such:
Now if you want to access one of the Nextstruct members, you use
Now, if you want to access the PrevStruct member of the Nextstruct[0] struct, what would you use? This is how it is done in the re-volt sources.
This will compile without errors, but unfortunately the program will crash because of Access Violation. So here are my 2 questions:
- Can anyone think of a reason why this is done in the source?
- What is the alternative to this code which would work (and not cause Access Violation error + crash) ?
For additional information, such code is used in rv2.zip\Xbox\Src\ainode.cpp - SetupNewMethodLinkNodes() lines 532 to 545.
Suppose there is a structure like this. As you can see, the 4 members of the structure are pointers to the same type as the struct itself.
Code: Select all
struct STRUCT {
STRUCT *PrevStruct[2];
STRUCT *NextStruct[2];
};
Code: Select all
STRUCT *TestStruct;
TestStruct = (STRUCT *) malloc(sizeof(TestStruct) * int NumStructs);
Now if you want to access one of the Nextstruct members, you use
Code: Select all
TestStruct->NextStruct[0];
Code: Select all
TestStruct->NextStruct[0]->PrevStruct[0];
- Can anyone think of a reason why this is done in the source?
- What is the alternative to this code which would work (and not cause Access Violation error + crash) ?
For additional information, such code is used in rv2.zip\Xbox\Src\ainode.cpp - SetupNewMethodLinkNodes() lines 532 to 545.