Re: pointer conversion



In article <K6mdnV5WebJ360XbnZ2dneKdnZydnZ2d@xxxxxx>,
Malcolm McLean <regniztar@xxxxxxxxxxxxxx> wrote:

Yes, to be a successful pedant you've got to be absolutely, precisely
accurate.

Clearly if the pointer is misaligned, adding sizeof(*ptr) will preserve the
(mis) alignment.

No. If you're a real pedant, you will observe that the undefined
behaviour of creating the misaligned pointer could be that the addition
produces an aligned one.

But the example wasn't a misaligned pointer - it was that the addition
produced a pointer outside of the object.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
.



Relevant Pages

  • Re: realloc() implicit free() ?
    ... block size as a request for one byte, and let the alignment mechanisms raise it as they will. ... is therefore suitably aligned for any type (`struct s' in particular), the value can be assigned to any type of pointer, and can then be used to access an object of that type. ... of the Standard can distort its meaning. ...
    (comp.lang.c)
  • Re: struct and union alignment
    ... > a char object requires only 1-byte alignment. ... I see no reason to require same alignment for types void* and char*, ... (Alignment requirements for character types are discussed ... See for yourself: in both cases "pointer ...
    (comp.lang.c)
  • Re: "free space" with declared type (alignment discussion)
    ... >>a function pointer member, a struct pointer member, and maybe a few ... > It doesn't put any extra constraint on alignment beyond this. ... > To assess actual alignment constraints, a structure might be used to figure how ...
    (comp.lang.c)
  • Re: malloc() and alignment
    ... void *my_malloc ... Standard says that "The pointer returned if the allocation succeeds is ... Standard provides no other way. ... All types apart from structures have an alignment of 1 ...
    (comp.lang.c)
  • Re: How does C cope if architecture doesnt address bytes?
    ... >>which the malloc() call occurs, figure out the type of the pointer which ... alignment in the implementation, rather than in either part of it. ... compiler and library are so strictly separate that there is no ... # The pointer returned if the allocation succeeds is suitably aligned so ...
    (comp.lang.c)