delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/02/08/05:21:11

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-ID: <0BA32251E589D2118EA60008C70DDCAB025F91A5@JNJFRISEXS1.eu.jnj.com>
From: "Baribaud, Christophe [JNJFR]" <CBARIBAU AT jnjfr DOT JNJ DOT com>
To: "'djgpp AT delorie DOT com'" <djgpp AT delorie DOT com>
Subject: RE: Alignment problem
Date: Fri, 8 Feb 2002 10:50:33 +0100
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2653.19)
Reply-To: djgpp AT delorie DOT com

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C1B086.0CD69420
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

>> If gcc's library permits this (and I don't believe so) it is not the =
=3D
>> case for other C compilers.

>This has nothing to do with the compiler: malloc is implemented in
>the library.

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.

-----Message d'origine-----
De : Eli Zaretskii [mailto:eliz AT is DOT elta DOT co DOT il]
Envoy=E9 : vendredi 8 f=E9vrier 2002 09:06
=C0 : djgpp AT delorie DOT com
Objet : Re: Alignment problem


> From: "Baribaud, Christophe [JNJFR]" <CBARIBAU AT jnjfr DOT JNJ DOT com>
> Date: Fri, 8 Feb 2002 07:23:47 +0100=20
>=20
> It seems that you consider that malloc should return an aligned =3D
> pointer. It has never been the case...

Of course, it was.  malloc should return a buffer aligned on 8-byte
boundary for any allocation whose size is greater than 8.  Even if
some other impementations of malloc don't guarantee that (I think
most if not all do), the DJGPP implementation should, since the x86
processors impose a significant penalty on unaligned accesses.

> If gcc's library permits this (and I don't believe so) it is not the =
=3D
> case for other C compilers.

This has nothing to do with the compiler: malloc is implemented in
the library.

------_=_NextPart_001_01C1B086.0CD69420
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2654.19">
<TITLE>RE: Alignment problem</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2>&gt;&gt; If gcc's library permits this (and I don't =
believe so) it is not the =3D</FONT>
<BR><FONT SIZE=3D2>&gt;&gt; case for other C compilers.</FONT>
</P>

<P><FONT SIZE=3D2>&gt;This has nothing to do with the compiler: malloc =
is implemented in</FONT>
<BR><FONT SIZE=3D2>&gt;the library.</FONT>
</P>

<P><FONT SIZE=3D2>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.</FONT></P>

<P><FONT SIZE=3D2>-----Message d'origine-----</FONT>
<BR><FONT SIZE=3D2>De : Eli Zaretskii [<A =
HREF=3D"mailto:eliz AT is DOT elta DOT co DOT il">mailto:eliz AT is DOT elta DOT co DOT il</A>]</FONT>=

<BR><FONT SIZE=3D2>Envoy=E9 : vendredi 8 f=E9vrier 2002 09:06</FONT>
<BR><FONT SIZE=3D2>=C0 : djgpp AT delorie DOT com</FONT>
<BR><FONT SIZE=3D2>Objet : Re: Alignment problem</FONT>
</P>
<BR>

<P><FONT SIZE=3D2>&gt; From: &quot;Baribaud, Christophe [JNJFR]&quot; =
&lt;CBARIBAU AT jnjfr DOT JNJ DOT com&gt;</FONT>
<BR><FONT SIZE=3D2>&gt; Date: Fri, 8 Feb 2002 07:23:47 +0100 </FONT>
<BR><FONT SIZE=3D2>&gt; </FONT>
<BR><FONT SIZE=3D2>&gt; It seems that you consider that malloc should =
return an aligned =3D</FONT>
<BR><FONT SIZE=3D2>&gt; pointer. It has never been the case...</FONT>
</P>

<P><FONT SIZE=3D2>Of course, it was.&nbsp; malloc should return a =
buffer aligned on 8-byte</FONT>
<BR><FONT SIZE=3D2>boundary for any allocation whose size is greater =
than 8.&nbsp; Even if</FONT>
<BR><FONT SIZE=3D2>some other impementations of malloc don't guarantee =
that (I think</FONT>
<BR><FONT SIZE=3D2>most if not all do), the DJGPP implementation =
should, since the x86</FONT>
<BR><FONT SIZE=3D2>processors impose a significant penalty on unaligned =
accesses.</FONT>
</P>

<P><FONT SIZE=3D2>&gt; If gcc's library permits this (and I don't =
believe so) it is not the =3D</FONT>
<BR><FONT SIZE=3D2>&gt; case for other C compilers.</FONT>
</P>

<P><FONT SIZE=3D2>This has nothing to do with the compiler: malloc is =
implemented in</FONT>
<BR><FONT SIZE=3D2>the library.</FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C1B086.0CD69420--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019