by refractor » May 27, 2002 @ 9:51am
A lot of it will be compiler specific.
However, my guesses would be:
1) No idea - I'd /presume/ no performance hit 'cos it's more a compiler directive than actual code.
2) In theory, creating a pointer to the structure only performs one dereference to the object, and will then use offsets to address the individual items.
The other way, you *might* be unlucky and have the compiler dereference the object twice... but any decent compiler should keep the dereferenced pointer cached for next use.
... it really does depend on the compiler. If you want to compile that bit of code as ARM and post it here, I/somebody can tell you which it's doing.
(Go to project ->C/C++->Category tab->Listing files-> Assembly with source code).. then look through the assembler files and chop and post the function.
3) We've been through this one before, IIRC. A switch will essentially compile to a large set of elseif statements. The best gain is to *order* the ifs/switches in the most frequent first.
If you've got quite a lot of items to check, use a switch - it's cleaner to read.
Cheers,
Refractor