When trying to use two pointers declared as a struct type, the code compiles fine, but at the first reference to the structure declared last, the program crashes with (I think) exception code
0xc0000005. As far as I can tell, this seems to be EXCEPTION_ACCESS_VIOLATION.
I'm using mingw 5.1.4 under Windows XP SP2. The problem code follows:
1 2 3 4 5 6 7 8 9 10 11 12
|
struct vertex {
int x;
int y;
};
int main(int argc, char *argv[]) {
vertex *A;
vertex *B;
A->x = 1;
B->x = 2;
}
|
This code compiles with no errors or warnings.
In this code, line 10 is causing the exception. If I swap lines 7 and 8, then the line 9 causes the exception. I've tried defining two structs, vertex and vertey, both with identical members, and declaring *A as vertex and *B as vertey; this results in the same problem at line 10.
If I declare them as variables, rather than pointers (and replace -> with .) there are no problems. If I remove either declaration (and all references to it), there are no problems.
Am I allowed only one pointer to a struct? Or am I missing something else?