| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Re: A fussy structure size |
Hello Andrew,
AM> I am working with a structure at the moment that seems to like even
AM> numbers!
That's right, it should be!
AM> I have created a structure in a program
AM> that I am writing composed of integers, unsigned shorts, unsigned chars,
AM> chars, and char arrays. The problem is that I work out the structure
AM> size to be 187
AM> bytes, but sizeof(structure) is returning 188 bytes.
AM> Fine I say to myself - I knocked out one of the characters in the final
AM> character array (therefore dropping one byte) and sizeof reports 186. I
AM> KNOW that a character is one byte (otherwise my other calcs would be way
AM> off the mark) so can someone give me an idea why sizeof insists on
AM> returning an even number?
A pad byte has been inserted into your structure so that all of its
components are properly aligned. Word addresses must be even, or the CPU
will spew if you do a 16 bit operation on it. See the K&R C manual, Section
6.4, p.138 in the ANSI 2nd edition, for more info.
Hope this helps,
Michael.
--- Blue Wave/RA v0.7 Q-Blue
* Origin: The Three Amigas - better than two (3:713/615.0)SEEN-BY: 3/1 2 4 5 6 54/54 99 711/401 430 807 808 809 932 934 712/623 627 SEEN-BY: 713/111 317 601 611 615 618 700 729 888 906 714/906 @PATH: 713/615 888 54/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™.