home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / c / 12234 < prev    next >
Encoding:
Text File  |  1992-08-12  |  1.1 KB  |  33 lines

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