11-01-2011, 11:55 AM
Rule 18.2 references two undefined behaviours that are described in the C90 standard. Undefined 34 relates to assignment of overlapping objects. Undefined 55 relates to copying memory using library functions other than memmove (this function is designed to permit overlapping memory areas to be copied). The rule therefore covers both assignment and copying using library functions.
The standard defines assignment between overlapping objects only when both objects overlap exactly and have the compatible types, ignoring type qualifiers. Therefore, assigning one member of a union to another member of the same union would seem to be well defined and is therefore permitted by Rule 18.2, although unions are not permitted by Rule 18.4.
The standard defines assignment between overlapping objects only when both objects overlap exactly and have the compatible types, ignoring type qualifiers. Therefore, assigning one member of a union to another member of the same union would seem to be well defined and is therefore permitted by Rule 18.2, although unions are not permitted by Rule 18.4.
Posted by and on behalf of the MISRA C Working Group