Remove undefined behavior in offset computation

Closes #156
Merge pull request #292 from cmr/offset_of

Remove undefined behavior in offset computation