home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!mips!darwin.sura.net!jvnc.net!princeton!astro!udalski
- From: udalski@astro.Princeton.EDU (Andrzej Udalski)
- Subject: Memory alignment of struct elements
- Message-ID: <1992Aug12.133132.10723@Princeton.EDU>
- Originator: news@nimaster
- Sender: news@Princeton.EDU (USENET News System)
- Nntp-Posting-Host: astro.princeton.edu
- Organization: Princeton University
- Date: Wed, 12 Aug 1992 13:31:32 GMT
- Lines: 20
-
- I am writing the software for a big database and the space is very
- important. If I try to use a
-
- struct { char ch ; float f }
-
- the compiler (both in SunOS 4.0.1 and Interactive SYSVR3) allocates
- 8 bytes for it, starting the "f" element at fifth byte of the structure.
- This makes both reading and writing such records from/to a binary database
- file (consisting of 5-byte-long records) very inconvinient, requiring
- a declaration of character array of 5 bytes and using "memcpy()". Is there
- a way to force the compiler to align the struct elements following their
- true length?
-
- Any help will be appreciated.
-
- Andrzej Udalski,
- Warsaw Univ. Observatory,
- Warsaw, Poland.
-
-
-