Comment on Ask HN: Favorite pointer tricks in C?parentComments−mansr15yThere are at least three common mistakes involving tricks like this:1. Alignment. Many CPUs will trap (or worse) if accessing a 32-bit quantity at a non-aligned address.2. Endianness. Needless to say, the 32-bit value read for a given string depends on the machine endianness.3. Aliasing. Casting between different pointer types can result in a violation of the C aliasing rules and, with a little bad luck, incorrect results.−jallmann15yGood to see you on hn.
Comments
There are at least three common mistakes involving tricks like this:
1. Alignment. Many CPUs will trap (or worse) if accessing a 32-bit quantity at a non-aligned address.
2. Endianness. Needless to say, the 32-bit value read for a given string depends on the machine endianness.
3. Aliasing. Casting between different pointer types can result in a violation of the C aliasing rules and, with a little bad luck, incorrect results.
Good to see you on hn.