X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f Message-ID: <3C63F73A.3FEF6F56@cyberoptics.com> Date: Fri, 08 Feb 2002 10:05:14 -0600 From: Eric Rudd Organization: CyberOptics X-Mailer: Mozilla 4.72 [en] (Win95; U) X-Accept-Language: en,pdf MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Alignment problem References: <0BA32251E589D2118EA60008C70DDCAB025F91A5 AT JNJFRISEXS1 DOT eu DOT jnj DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 28 NNTP-Posting-Host: 65.214.97.102 X-Trace: 1013184314 reader0.ash.ops.us.uu.net 5648 65.214.97.102 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "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