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: 103376,d233b131fc3b7ba7 X-Google-Attributes: gid103376,public From: Keith Thompson Subject: Re: Help: Storage size Date: 1999/07/14 Message-ID: #1/1 X-Deja-AN: 501125738 References: <7mejue$9lk$1@nnrp1.deja.com> <7mf7lp$c9g@hobbes.crc.com> <7mfndb$mc8$1@nnrp1.deja.com> X-Complaints-To: usenet@nusku.cts.com X-Trace: nusku.cts.com 931995496 2269 198.68.168.21 (14 Jul 1999 23:38:16 GMT) Organization: CTS Network Services NNTP-Posting-Date: 14 Jul 1999 23:38:16 GMT Newsgroups: comp.lang.ada Date: 1999-07-14T23:38:16+00:00 List-Id: Adrian Hoe writes: > In article <7mf7lp$c9g@hobbes.crc.com>, > "David C. Hoos, Sr." wrote: [...] > > 3. If unsigned short is 16 bits on your system, the bit-field > > specification (:16) would appear to be redundant. > > Most platforms have 16 bits for unsigned short. The bit-field > specification (e.g. :16) is used to ensure 16 bits mapping on other > platform(s). In purely C terms, this is a bad idea. The C standard allows a bit-field to be of type int, signed int, or unsigned int (in this context only, it's implementation-defined whether a plain "int" is signed or unsigned). Thus an unsigned short bit-field is, strictly speaking, illegal -- though many (most?) implementations will accept it as an extension. (Try compiling your C source with "gcc -ansi -pedantic -Wall".) Many other aspects of bit-fields are either implementation-defined or unspecified. If you want a C integer type of a specified width, it's usually best to declare it as a typedef whose definition varies from one system to another. C9X, the next revision of the C standard, will provide such typedefs in the new predefined header , but you can easily roll your own. Part of the job of porting your code to another architecture is then updating the typedefs. (Be sure to include some automated checking code to make sure you got it right.) Once you've done this, matching the C integer types to corresponding Ada types is pretty easy. For example, an Ada 16-bit unsigned type can be declared as: type Unsigned_16 is mod 2**16; for Unsigned_16'Size use 16; The exact layout of record components / struct members is implementation-defined in both languages. Using pragma Convention(C) on the Ada side should guarantee that they match. The only real drawback of this approach is that not all platforms actually have a 16-bit integer type. In the unlikely event that this becomes an issue (for example, on some Crays), I suppose you can always fall back to bit-fields. -- Keith Thompson (The_Other_Keith) kst@cts.com San Diego Supercomputer Center <*> One of the great tragedies of ancient history is that Helen of Troy lived before the invention of the champagne bottle.