Barry Schwarz <
schw...@dqel.com> writes:
> [for memcpy() when there is overlap between the operands,
> would the behavior still be undefined if the explict
> statement of undefined behavior were not present?]
>
> That would be unspecified behavior. In this case, the standard
> specifically states that the behavior is undefined.
I won't disagree, but there is another point to be considered
here. In C90 I believe this conclusion is right - without the
explicit statement of undefined behavior the result would be
unspecified behavior. However, in C99/C2011, the specification
for memcpy() includes 'restrict' qualifiers on the parameters. A
case could be made that the rules for 'restrict' suffice to show
undefined behavior when the operands overlap, and the statement
of explicit undefined behavior is just a carryover from C90 which
did not have 'restrict'. The case is not airtight since what it
means for standard library function prototypes to use 'restrict'
is AFAICT never spelled out in the Standard, but it seems
reasonable to infer that 'restrict' in such cases means the
corresponding function may be or will be defined with the same
'restrict' qualifiers. If that is so then we may deduce that
overlapping operands result in undefined behavior without needing
an explicit statement to that effect.
In any case, good observation on the original point.