From: oak9755 AT silver DOT sdsmt DOT edu (Olav Kindt) Newsgroups: comp.os.msdos.djgpp Subject: Re: Problem with data alignments... Date: 4 Nov 1996 09:22:22 GMT Organization: South Dakota School of Mines and Technology Lines: 43 Distribution: world Message-ID: <55kcke$r6b@news.sdsmt.edu> References: <01bbca0a$0f930e40$a5fd82c1 AT pz43 DOT dial DOT pipex DOT com> NNTP-Posting-Host: silver.sdsmt.edu DJ-Gateway: from newsgroup comp.os.msdos.djgpp Apparently-To: djgpp AT delorie DOT com ~^Fozz^~ (fozz AT dial DOT pipex DOT com) wrote: : Hi All, : I'm quite new at C, although I have been programming in assembly for quite : some time now, so I'm not new to programming concepts. However I have : experienced a small problem with DJGPP and was wondering if there was any : way around it .... The problem is with alignment of data within structures, : if I have a structure of a word then a long word, the first word is rounded : up to a long word in size for the structure variable....eg.. : : struct test { : short var1; : long var2; : }; : : here if I do a ... sizeof(struct test) ... it returns a size of 8 bytes ! : -- it rounds Var1 up to a long -- anyone know how to get it to keep Var1 as : a word ? : Hi there, DJGPP will pad the structures so that they are aligned on 32-bit boundaries, to speed up memory access. I think your word will still be recognized as a word, it just doesn't use the space between the variables (Somebody please verify this, or coorect me if i'm wrong) You can avoid this alignment byt specifying __attribute__ __((packed))__ at the end of each line in the structure definition. struct test { short var1 __attribute__ __((packed))__; long var2 __attrinbute__ __((packed))__; }; Someone posted here i few weeks back that you didn't have to specify this on every line, but rather on the end or something. Check the FAQ at 22.9 for more info on this topic. Olav Kindt | email: oak9755 AT silver DOT sdsmt DOT edu 737 E. Anamosa Street #103 | xedb_oak AT debet DOT nhh DOT no Rapid City SD-57701 | MAIL me man.......