You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a value is copied into an object having no declared type using memcpy or memmove, or is copied as an array of character type, then the effective type of the modified object for that access and for subsequent accesses that do not modify the value is the effective type of the object from which the value is copied, if it has one.
I read "or is copied as an array of character type," to be modifying "using memcpy or memmove" and not modifying "having no declared type".
In many cases, we use memcpy to transfer the contents of something of a buffer of an unstructured type (e.g. a byte array) into a structured value (e.g. a struct or a uint32_t). From the above, it is only (guaranteed to be) valid to do this when the destination has a declared type. In practice, that means that we can only safely use this pattern when the destination is a local variable.
The text was updated successfully, but these errors were encountered:
Here's a good way to make it easy to verify the code is correct in this respect: For every use of memcpy copying a value to another value of the same type T, create a wrapper function:
Some version of the C standard says:
I read "or is copied as an array of character type," to be modifying "using memcpy or memmove" and not modifying "having no declared type".
In many cases, we use
memcpy
to transfer the contents of something of a buffer of an unstructured type (e.g. a byte array) into a structured value (e.g. a struct or a uint32_t). From the above, it is only (guaranteed to be) valid to do this when the destination has a declared type. In practice, that means that we can only safely use this pattern when the destination is a local variable.The text was updated successfully, but these errors were encountered: