3 ms·
Yes, I'm sure. Here is a blog post by one of the leading professors of undefined behavior about this: https://blog.regehr.org/archives/959 https://blog.regehr.
by wolf550e 9y ago
Yes, I'm sure. Here is a blog post by one of the leading professors of undefined behavior about this:
https://blog.regehr.org/archives/959 https://blog.regehr.org/archives/959
(edited to better blog post by same author)
- userbinator 9y agoAFAIK, and also in the examples shown with that blog post, all the problems with strict aliasing involve reading/writing the same object with separate differently-typed pointers. In my example, I'm only accessing s as a uint32_t*, so there is nothing to "alias" per se.
- wolf550e 9y agoBut `s` is defined somehow, and it is not defined as a `uint32_t * ` (or else you would not need the cast). It is usually defined as `char * `. The memory being read is reachable by dereferencing `s`, a `char * `, and by dereferencing `(uint32_t * )s`, a `uint32_t * `. Thus, type punning and aliasing. Each byte of memory should be reachable only by pointers/array indexes of a single type (and anything that is not a `char * ` can be accessed by `char * `).
- deleted 9y ago[deleted]