Where is the UB? Looks ok to me.
-
-
Replying to @RichFelker
With dynamically allocated memory, the effective type is reset by new writes. When called from caller2, after line 8, that part of memory is an array of unsigned char, it's wrong to read it as a float.
2 replies 0 retweets 1 like -
Replying to @volatile_void
I'd need to look up the specifics but the intent is clearly that memcpy-type operations work, and that it's valid to treat the effective type as any (one) type you produced a valid representation for.
2 replies 0 retweets 0 likes -
Replying to @RichFelker @volatile_void
WG14 is of course notoriously bad at expressing intent and notoriously bad at admitting they expressed it wrong or imprecisely and fixing it...
1 reply 0 retweets 0 likes -
Replying to @RichFelker @volatile_void
By your argument, memcpy and memset wouldn't work at all on allocated storage.
1 reply 0 retweets 0 likes -
Replying to @RichFelker
memcpy copies the effective type. memset falls in “For all other accesses to an object having no declared type, the effective type of the object is simply the type of the lvalue used for the access.”
2 replies 0 retweets 0 likes -
Replying to @volatile_void
The memcpy function is not special. Doing the equivalent with your own char writes is equally valid.
1 reply 0 retweets 0 likes -
Replying to @RichFelker
I think this is what C11 means with “using memcpy or memmove, or is copied as an array of character type”, but then am I allowed to compute the values of the chars off-line as I did in the first function f? How about the third example below? https://godbolt.org/g/5pMB7c pic.twitter.com/ckdBQ4V69E
1 reply 0 retweets 0 likes -
Replying to @volatile_void
There is no consistent interpretation possible without acknowledging/allowing that allocated storage can have *ambiguous* effective type.
2 replies 0 retweets 0 likes -
Replying to @RichFelker @volatile_void
I'm not 100% sure but my suspicion is that you can't make it consistent without leaving the effective type to be determined by the lvalue used for next access after any stores via char types have occurred.
1 reply 0 retweets 0 likes
IOW same as the memset case.
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.