Alignment of foo[1][1][1][1]

H

Harald van Dijk

  int i;
  double *p;
  p = (double *) &i;
  assert((int *) p == &i);
However, that is the _only_ guarantee made about the value of p. Since
dereferencing p is not allowed in strictly conforming programs anyway,
the standard does not need to, and does not, address the question of
whether p points to any object at all.

[...]

I don't believe the standard guarantees that at all.

As before in this thread, a part of the sentence is missing. The point
was that the standard requires that the assert passes, if &i is
suitably aligned for a pointer of type double *. Sorry for the
confusion.
 
K

Keith Thompson

Harald van Dijk said:
  int i;
  double *p;
  p = (double *) &i;
  assert((int *) p == &i);
However, that is the _only_ guarantee made about the value of p. Since
dereferencing p is not allowed in strictly conforming programs anyway,
the standard does not need to, and does not, address the question of
whether p points to any object at all.

[...]

I don't believe the standard guarantees that at all.

As before in this thread, a part of the sentence is missing. The point
was that the standard requires that the assert passes, if &i is
suitably aligned for a pointer of type double *. Sorry for the
confusion.

Hmm, I hadn't realized that round-trip pointer-to-pointer conversion is
guaranteed to yield the original value if the alignment is ok (C99
6.3.2.3p7). (I'm sure I had read that paragraph; I just forgot about
it.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top