Mail Archives: djgpp/2002/02/08/11:15:09
"Baribaud, Christophe [JNJFR]" wrote:
> Yes, of course, but what I wanted to explain is that it is generally
> dangerous to assume that malloc returns aligned memory when writing
> portable code. I haven't heard about a standard, libc is one of the
> possible libraries implementing malloc.
Actually, the thing that is dangerous in portable code is to perform
arithmetic on the pointer to align it -- which is why malloc ought to be
doing this. I have an "alignptr" subroutine similar to Mr. Baribaud's
code, and I'm using it as a work-around, but it is not only a nuisance
to call it after every malloc, it's also less portable. I agree with
Eli that this is a "quality of implementation" issue.
It was pointed out that my diagnostic code was non-portable, but that's
beside the point, since this is a problem specific to DJGPP.
Furthermore, disassembly of the code revealed that it was manipulating
the pointer as intended.
A note to those attempting to reproduce these problems: the alignments
seem to be random, so that a single trial of the program is
insufficient. After several runs, I was about to conclude that the
pointers *were* properly aligned under Win95, until I closed the DOS
box, ran and closed a Windows program, opened a new DOS box, and ran my
program again. Then the pointers were only 4-byte aligned.
-Eric Rudd
- Raw text -