Typecasting

Discussion in 'C' started by bughunter2, Feb 27, 2007.

  1. bughunter2

    bughunter2 New Member

    Joined:
    Feb 27, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Netherlands
    Home Page:
    http://reversemasters.nl/
    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?
     
  2. bughunter2

    bughunter2 New Member

    Joined:
    Feb 27, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Netherlands
    Home Page:
    http://reversemasters.nl/
    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
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    In the second example, you're not casting pMem, you're casting pMem->e_lfanew.
    EDIT: Woops, you found it while I was posting.
     
  4. bughunter2

    bughunter2 New Member

    Joined:
    Feb 27, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Netherlands
    Home Page:
    http://reversemasters.nl/
    yep, thanks though :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice