4 ms·
The string literal is (all but -- honestly I'm not sure what the standard says here) guaranteed to be aligned naturally for the platform. The thing on the left
by ajross 15y ago
The string literal is (all but -- honestly I'm not sure what the standard says here) guaranteed to be aligned naturally for the platform. The thing on the left hand side is not. If it's a pointer to a heap block, you're fine. If it's a pointer to a token parsed out of string input, it can be anything.
Even architectures that support misaligned accesses can be configured to trap on them and generate unexpected fatal signals.
- brigade 15y agoNatural alignment for string literals is generally 1 byte. Natural alignment for uint32_t is generally 4 bytes.
- tptacek 15y agoSorry, I wasn't talking about the string literal; I was talking about the buffer you're comparing it to. I'm saying: yes, you're right, you have to be careful that it's aligned.