Posted By: Rei_Ayanami
Struct Casting - 02/25/12 19:42
Hello!
I possibly just discovered a bug:
When I am casting a void * to a struct pointer and then try to access an element, it does not return the desired member. When I however create a struct pointer and assign this pointer to the void * and then access the members, everything is okay. Both versions work in C++ (tested by copy/paste)
The problem occurred this way:
I have a struct that contains a void pointer (and some other things). The void * points to a struct instance. The struct, it points to, consists of 2 ints.
The following code does not work, and returns the same variable diags the same variable two time.
However, this does work and returns the real content of the second variable:
As already said, I am not sure if I am wrong, but I assume that the code is right, as it works in C++.
Thanks,
Marian Frische
I possibly just discovered a bug:
When I am casting a void * to a struct pointer and then try to access an element, it does not return the desired member. When I however create a struct pointer and assign this pointer to the void * and then access the members, everything is okay. Both versions work in C++ (tested by copy/paste)
The problem occurred this way:
I have a struct that contains a void pointer (and some other things). The void * points to a struct instance. The struct, it points to, consists of 2 ints.
The following code does not work, and returns the same variable diags the same variable two time.
Code:
diag_var("\nUnscaledScreenWidth -> %.0f", (((ESscreenStruct*)testDefStruct->specific)->unscaledScreenWidth)); diag_var("\nUnscaledScreenHeight-> %.0f", (((ESscreenStruct*)testDefStruct->specific)->unscaledScreenHeight));
However, this does work and returns the real content of the second variable:
Code:
ESscreenStruct *tempStruct = testDefStruct->specific; diag_var("\nUnscaledScreenWidth -> %.0f", tempStruct->unscaledScreenWidth); diag_var("\nUnscaledScreenHeight-> %.0f", tempStruct->unscaledScreenHeight);
As already said, I am not sure if I am wrong, but I assume that the code is right, as it works in C++.
Thanks,
Marian Frische