home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.std.c
- Path: 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
-
-
- 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
-