Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Typecasting (http://www.go4expert.com/forums/typecasting-t3182/)

bughunter2 28Feb2007 04:05

Typecasting
 
I've got a question about typecasting.

The next two lines of C code, do not give any error:
Code:

IMAGE_DOS_HEADER * image_dos_header = (IMAGE_DOS_HEADER *) pMem;
fseek(fHandle, image_dos_header->e_lfanew, SEEK_SET);

And this line does give an error:
Code:

fseek(fHandle, (IMAGE_DOS_HEADER *)pMem->e_lfanew, SEEK_SET);
The error is 'error: request for member `e_lfanew' in something not a structure or union'
Hmm? I used the exact same cast as in the other line.

Somebody got an idea on this one?

bughunter2 28Feb2007 05:12

Re: Typecasting
 
nvmind guys(or girls)

i found it out by myself:

Code:

fseek(fHandle, ((IMAGE_DOS_HEADER *)pMem)->e_lfanew, SEEK_SET);
only 1 line of code and it works now, i just needed to make sure the compiler evaluated the typecast after making it using these '(' ')' chars

DaWei 28Feb2007 06:59

Re: Typecasting
 
In the second example, you're not casting pMem, you're casting pMem->e_lfanew.
EDIT: Woops, you found it while I was posting.

bughunter2 28Feb2007 13:57

Re: Typecasting
 
yep, thanks though :)


All times are GMT +5.5. The time now is 07:18.