Article View: comp.std.c
Article #3307Is this allowed in C?
From: peter curran
Date: Tue, 26 Jan 1993 12:08
Date: Tue, 26 Jan 1993 12:08
36 lines
1741 bytes
1741 bytes
In <1993Jan22.012502.5241#nntpd.lkg.dec.com> diamond@jit533.jit.dec.com
(Norman Diamond) writes..
[original problem deleted]
ND>The C standard guarantees that whenever malloc() succeeds ... the
ND>value will point to storage suitably aligned for everything,....
This leads me to a question:
void *p;
p = malloc(1);
Are there any alignment restrictions on the allocated memory?
Assuming, for example, sizeof(double) > 1, a double cannot be
stored here, so does the memory have to be suitably aligned for
use as a "double *?" Section 4.10.3 appears to me to be
sufficiently ambiguous that this is unclear.
I have on occasion needed addresses to serve as "markers"
(addresses that will not match any real object, nor NULL), and
have accomplished this by allocating objects that will never
really be used. I could save some (probably trivial amount of)
memory by allocating single bytes for the purpose, but was
never sure that something strange couldn't happen if the
address wsan't properly aligned, even if nothing tried to
derefernce it.
Peter Curran FidoNet: 1:229/15
Usenet: peter.curran@canrem.com RIME: CRS (#118)
---
þ DeLuxeý 1.25 #12339 þ
--
Canada Remote Systems - Toronto, Ontario
World's Largest PCBOARD System - 416-629-7000/629-7044
Technical Details
Message-ID:
<1993Jan26.4502.4824@dosgate>Path:
arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!canrem!dosgate!dosgate![peter.curran@canrem.com]Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c Path: arc1-ca.pugleaf.net!sparky!uunet!uunet.ca!canrem!dosgate!dosgate![peter.curran@canrem.com] From: "peter curran" <peter.curran@canrem.com> Subject: Is this allowed in C? Message-ID: <1993Jan26.4502.4824@dosgate> Reply-To: "peter curran" <peter.curran@canrem.com> Organization: Canada Remote Systems Distribution: comp Date: 26 Jan 93 07:08:35 EST Lines: 36