Article View: comp.lang.c.moderated
Article #2566Re: void* type
From: Jim Trigg
Date: Tue, 09 Apr 1996 22:40
Date: Tue, 09 Apr 1996 22:40
36 lines
1907 bytes
1907 bytes
In article <4kcmqc$p5f@solutions.solon.com> news@Thinkage.On.CA writes: > fred@genesis.demon.co.uk writes: >> In article <4k1q3p$5bj@solutions.solon.com> news@Thinkage.On.CA >> writes: >>> to a double *. Since malloc guarantees alignment (actually, only >>> *after* casting, but only a very malicious malloc would do that to >>> you), this can safely be done. >> The standard actually says 7.10.3: >> "The pointer returned if the allocation succeeds is suitably >> aligned so that it may be assigned to a pointer to any type of >> object..." >> So the alignment is guaranteed for the pointer returned i.e. prior >> to conversion. > No, it only says that you can do the assignment, i.e., it won't > cause a trap or somesuch. The assignment itself might change the > pointer value. After the assignment eveything must be as we all > expect. Imagine a malloc that returns a pointer to a non-aligned > byte, and the casting works by rounding forward to the next > alignment boundary. Actually, in that case, malloc would have to reserve more space than you requested -- so that from the next alignment boundary to the end of reserved space was at least the amount of memory requested. malloc() is much more likely, IMHO, to begin each memory region on a properly aligned boundary. Just a Thought, Jim Trigg
Technical Details
Message-ID:
<4kep0p$8ck@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jv7ge$d49@solutions.solon.com> <4k1q3p$5bj@solutions.solon.com> <4k619q$aq4@solutions.solon.com> <4kcmqc$p5f@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: jyacc!marks!jtrigg@uunet.uu.net (Jim Trigg) Newsgroups: comp.lang.c.moderated Subject: Re: void* type Date: 9 Apr 1996 17:40:25 -0500 Organization: JYACC, Inc. Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4kep0p$8ck@solutions.solon.com> References: <4jv7ge$d49@solutions.solon.com> <4k1q3p$5bj@solutions.solon.com> <4k619q$aq4@solutions.solon.com> <4kcmqc$p5f@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Nntp-Posting-Host: marks X-Newsreader: Gnus v5.1