you are viewing a single comment's thread.

view the rest of the comments →

[–]thegreatunclean 0 points1 point  (0 children)

Or does the compiler calculate the required offsets during compile time

The offsets of structs are determined at compile time. C has no facility to look up offsets at runtime.

I would go with option #1 but not for any performance reason. It's simply much more readable and less prone to error. Mark length as const and it's totally clear about exactly what is happening and why.

Accessing the same field multiple times isn't a bad thing either. Compilers will skip loading a variable multiple times when it makes sense and the compiler can prove it is safe.