From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f6aa,76b1fcc14e8dced X-Google-Attributes: gid10f6aa,public X-Google-Thread: 1014db,8b6c45fbebd7d3b7 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,c9c309a1859318a1 X-Google-Attributes: gid103376,public X-Google-Thread: 114917,76b1fcc14e8dced X-Google-Attributes: gid114917,public X-Google-Thread: 109fba,76b1fcc14e8dced X-Google-Attributes: gid109fba,public From: "Samuel T. Harris" Subject: Re: HELP ! need to insert value in array !! Date: 1997/06/30 Message-ID: <33B7EB21.446B@hso.link.com>#1/1 X-Deja-AN: 254392850 References: <33A9C27C.22F7@post4.tele.dk> <5oci49$97g@crl.crl.com> <866920621snz@genesis.demon.co.uk> <5p0v7l$9uc@nntp.seflin.org> Organization: Hughes Training Inc. - Houston Operations Newsgroups: comp.lang.c,comp.lang.c++,comp.os.msdos.programmer,comp.lang.asm.x86,comp.lang.ada Date: 1997-06-30T00:00:00+00:00 List-Id: I believe what is confusing here is that padding can be inserted for two reasons. One is because of the natural alignment of the data due to the particulars of the target machine. The other is due to some additional particular requirements when making arrays. Earlier, Mike Rubenstein wrote: > Perhaps it was someone who actually knows C. Whoever said it was > correct. Objects may be padded in that there may be bytes that are > not used, but there must be no additional padding between array > elements. For any type T, > > T a; > T b[5]; > > we must have sizeof b == 5 * sizeof a. There can be no unused space > between b[0] and b[1]. > > Michael M Rubenstein The compiler is allowed to "pad" the elements of the array, if and only if it "pads" scalar instances of the component type. Additional padding within the array is not permitted. This means, in a platform using 32-bit words, a struct taking 11 bits can be placed with 32-bit alignment. This includes 21 bits of "padding". An array of the same struct will place each 11-bit component in adjacent 32-bit words. Again, we have 21 bits of "padding" between the "contiguious" components of the array. This "padding" is natural to the component since it is natural to the scalar and is not considered "unused". Mark sited a standards reference ... > I am talking about things that are guaranteed in the standard. > Obviously, they are not things that "everyone knows must be so". > > I already quoted the relevant passage -- the elements of an array are > contiguous (ISO 6.1.2.5). his natural "padding" in my example must be preserved when creating arrays to satisfy the requirements and this "padding" does not violate the contiguous nature of the components in the array. Robert Dewar also states ... > i am not quite sure who said > > <<: An impelemenattion is not permitted to pad between array > elements.?? > But it is definitely wrong, of course an implementatoin is permitted > padding between array elements. ... in which I believe he is refering to this natural padding. (Please correct me, Robert, if I've misread you.) I expect the same default behavior in Ada (except for Booleans). I want my Ada arrays to lay out similarly to my scalars as far as alignment is concerned. I don't want my Ada adding any additional padding. I use pragma pack when I want Ada to collapse the "natural" or alignment padding and I expect to pay some performance penalty when I do so. -- Samuel T. Harris, Senior Engineer Hughes Training, Inc. - Houston Operations 2224 Bay Area Blvd. Houston, TX 77058-2099 "If you can make it, We can fake it!"