Martin said:
I can't see where you said that. In reply to my original question,
viz. "Is the following use of memcpy()
a well-defined way of so doing?" you replied "No, but it's not exactly
undefined either." I took that to mean it is not undefined.
There are several different kinds of behaviour described in the
Standard. They are:
* Unspecified behavior --- behavior, for a correct program construct
and correct data, for which the Standard imposes no requirements.
* Undefined behavior --- behavior, upon use of a nonportable or
erroneous program construct, of erroneous data, or of
indeterminately-valued objects, for which the Standard imposes no
requirements. [...]
* Implementation-defined behavior --- behavior, for a correct program
construct and correct data, that depends on the characteristics of
the implementation and that each implementation shall document.
* Locale-specific behavior --- behavior that depends on local
conventions of nationality, culture, and language that each
implementation shall document.
(C99 may add more - I haven't checked.)
If the Standard *fully* describes the behaviour of the construct, it is
considered to be "well-defined". Otherwise, the behaviour is one of the
others described above. It isn't locale-specific, for reasons that I
hope are obvious. It isn't implementation-defined, because the
implementation is not required to document which value your object will
take. The remaining possibilities are: undefined, unspecified, and
well-defined. It isn't well-defined because the value your object will
have after your memcpy cannot be determined solely by reference to the
Standard. So it's either unspecified or undefined.
To judge it 'undefined' would, I think, be harsh. After all, you
specified that sizeof(long) was 4, and I think it's fair to assume that
you would be happy to specify that CHAR_BIT is 8, so we're talking
about an object exactly 32 bits wide, and long ints must be at least
that wide anyway. You are giving precise values to three of the four
bytes in the long int, and the fourth is known to contain 0-bits. In no
case are you setting any byte in such a way that the sign bit will be
set, so that prospective complication is ruled out. So you're going to
end up with some legal value or other in your long int. The exact value
you get will depend, basically, on endianness (byte ordering), for
which the Standard doesn't impose any requirements on the
implementation.
So in /my/ judgement, the behaviour is neither well-defined,
implementation-defined, undefined, or locale-specific. That leaves
'unspecified' as the only remaining option.
Others here may disagree, of course!