TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Andrew Clarke
from: rowan crowe
date: 1995-06-24 19:21:10
subject: structure alignment

Answering msg from Andrew Clarke to Paul Edwards,
on Thursday June 22 1995 at 01:38

 PE>> I don't know.  Always code on the assumption that structures
 PE>> aren't aligned in a particular manner, and you will end up
 PE>> with portable code.  BFN.  Paul.

...

 AC> I wrote a small program to report sizeof(EZYMSGHDR).  Borland C++ 3.1
 AC> reported the correct size, 186 bytes; Microsoft QuickC 2.5 reported
 AC> 188 bytes, due to its default of 2-byte structure alignment.  Perhaps
 AC> it has something to do with EZYNETADDR being nested inside EZYMSGHDR.
 AC> I will investigate when I have some more time, but in my opinion the
 AC> behavior of QuickC's default structure aligning is unacceptable, based
 AC> on the above structure.

    This was something I was going to ask about; if structures are aligned
to word boundaries, then what happens when you need to interface a language
which doesn't? Your example shows a potential problem if one is not aware
of the compiler aligning the structures behind your back.

    I can understand the advantage of aligning structures which are used in
memory; but for writing to records on disk I consider it a big no-no.

---
* Origin: Jelly-Bean software development. (3:635/727.1)
SEEN-BY: 50/99 620/243 623/630 632/103 348 998 633/371 634/384 388 635/301
SEEN-BY: 635/502 503 544 727 636/100 639/100 711/401 409 410 430 510 807 808
SEEN-BY: 711/809 932 934 712/515 713/888 714/906 800/1 7877/2809
@PATH: 635/727 632/348 635/503 50/99 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.