tags:

views:

26

answers:

1

Assume I have the following:

Elf_FIle_Header *fileHeader //struct pointer, points to start of the Elf file header
fileHeader->offset //byte offset from start of file to section headers

Elf_Section_Header *sectionHeader = (Elf_Section_Header *)(char *)fileHeader + fileHeader->offset

Why doesn't the above line point me to the start of the section header table? How do I point to the start of the section header table?

A: 

Both type casts will have higher priority than the addition, so you will add to a Elf_Section_Header* using pointer arithmetics. Presumably you want:

Elf_Section_Header *sectionHeader = (Elf_Section_Header *)((char *)fileHeader + fileHeader->offset);

tengfred