In comp.std.c, article <. elte.hu>,
Ersek, Laszlo <> wrote:
> But what if we assume for a moment that the all-bits-zero representation
> carries a valid null pointer value for all pointer-to-object types? In
> that case, wouldn't zeroing out the individual bytes of a
> pointer-to-object object through a (char unsigned *) make (c) applicable?
It depends on how this is done. You could apply (c) under "If a value
[...] is copied as an array of character type". But note the words
"value" and "copied". This means that there is a source in memory
(with an effective type). While memcpy and memmove use such a source,
memset doesn't. I'm not such that even a "for" loop falls under this
condition because I don't see how an implementation could recognize
every form of such loops (in the most complicated cases).
> ----v----
> If a value is copied into an object having no declared type [...] 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.
> ----^----
> static double *dp; /* suppose all-bits-zero */
> static char unsigned zeroes[sizeof dp];
> static void
> z1(void **dpp)
> {
> (void)memcpy(dpp, &dp, sizeof dp);
> }
> static void
> z2(void **dpp)
> {
> size_t pos;
> assert(0 == memcmp(&dp, zeroes, sizeof zeroes));
> for (pos = 0u; pos < sizeof zeroes; ++pos) {
> ((char unsigned *)dpp)[pos] = zeroes[pos];
> }
> }
> static void
> z3(void **dpp)
> {
> (void)memset(dpp, 0, sizeof(double *));
> }
> (c) applies to z1().
and the effective type of the object in &dp (that is, double *)
is used.
> z2() copies the exact same bit pattern (object representation) from
> a character array to "*dpp".
But the object in zeroes has no effective type (except the individual
unsigned char), thus no value. You first need to force an effective
type (and a value), e.g. with
*((double **) &zeroes) = NULL;
Then I'm not sure that the for loop counts as a copy of such an
object.
> z3() establishes the exact same bit pattern (object representation)
> in "*dpp" without a source object.
Since there is no source, there is no effective type and no value.
> Insomuch as TC2 entry 9 has rendered z2() and z3() equivalent to z1() wrt.
> integers, without touching 6.5 at all,
??? Could you explain? I don't see such a thing on
http://www.open-std.org/jtc1/sc22/wg14/www/docs/tc2.htm
--
Vincent Lefèvre <> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)