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=0.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b23661223cdab88a,start X-Google-Attributes: gid103376,public From: Pascal MALAISE Subject: Re: Representation clauses and records Date: 1997/12/16 Message-ID: <349646A2.1A013246@alphalink.com.au>#1/1 X-Deja-AN: 298649761 Content-Transfer-Encoding: 7bit References: <347000b1.4909762@news.geccs.gecm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Alphalink Australia Newsgroups: comp.lang.ada Date: 1997-12-16T00:00:00+00:00 List-Id: Brian Orpin wrote: > The question is simple; when declaring a representation clause for a > record there is an optional alignment clause using 'mod at'. What effect > does this have on the component representation clause and how does this > relate to the storage size of the system? > > Having read the LRM I get the impression that it is to do with word > boundaries and alignment but I do not understand the implications of > using different values for the 'at mod' statement. Hope you know a little bit about C, this will help, but anyway. You expect to receive a message of max 100 bytes. You declare a buffer of 100 characters. You call whatever procedure to fill your buffer with the message. You discover that the beginning of the message is, in fact, an int. You use any C pointer cast or ADA unchecked conversion to "map" these first four bytes to an integer. In C or ADA, you are likely to get a bus error or an unaligned access, more or less recovered by the operating system or your application :-( This is because processors make assumptions about the addresses of given data types: character/byte - any address 16 bits "word" - address is a multiple of 2 32 bits "int" - address is is a multiple of 4 64 bits "long" - address is a multiple of 8 When you declare your array of bytes/characaters, the compiler implements the array starting at any address. When you cast, the compiler will consider the new (integer) data as aligned and the processor will trap. In C, the workaroud is to always define arrays of longs (64 bits) of the according size. In ADA, you can specify an alignment clause for your buffer/structure. Note that, however, compilers are intelligent: when you define a record or even a "union", the fields are implemented (alignment of first field + gaps for the others) to match the alignment requirements of each field. So, as long as you don't "cast" it should be OK. -- Pascal MALAISE | E-mail: 52 Fletcher St | (priv) malaise@alphalink.com.au HAWTHORN EAST VIC 3123 | (prof) malaise@thomson.starway.net.au AUSTRALIA