Mail Archives: djgpp/2002/02/08/04:49:55
> From: CBFalconer <cbfalconer AT yahoo DOT com>
> Newsgroups: comp.os.msdos.djgpp
> Date: Fri, 08 Feb 2002 08:49:31 GMT
>
> Of course you can do whatever you want on a cast to int. I'm not
> complaining about that. I'm just pointing out that it is
> undefined behaviour as far as the language is concerned.
The language standard (at least C99) does require malloc to return a
pointer that is suitably aligned for the types of object for which the
pointer could be used. In practice, for x86 CPUs, this means that any
object that is 8 bytes or larger needs to be aligned on 8-byte
boundary.
> On many systems, including segmented DOS, that cast would make no
> sense whatsoever.
I believe the purpose of the cast was to use the pointer in an
arithmetic expression (bitwise AND), that's all.
> So the test of the integer representation really says
> nothing about the alignment, except in particular implementations.
Right. But I believe the OP _was_ discussing a particular
implementation: the DJGPP implementation of malloc.
- Raw text -