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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,36c197595b07e443 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!e27g2000yqd.googlegroups.com!not-for-mail From: Martin Newsgroups: comp.lang.ada Subject: Re: Cross-platform issues Date: Tue, 8 Dec 2009 01:02:11 -0800 (PST) Organization: http://groups.google.com Message-ID: <1767f89d-083c-49ff-a9d5-3d56ef05cd9a@e27g2000yqd.googlegroups.com> References: NNTP-Posting-Host: 20.133.0.8 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1260262931 6548 127.0.0.1 (8 Dec 2009 09:02:11 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 8 Dec 2009 09:02:11 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: e27g2000yqd.googlegroups.com; posting-host=20.133.0.8; posting-account=g4n69woAAACHKbpceNrvOhHWViIbdQ9G User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:8345 Date: 2009-12-08T01:02:11-08:00 List-Id: On Dec 8, 12:33=A0am, tmo...@acm.org wrote: > > closely as possible to the one that inspired it. =A0The original > > emits trace data with things like field length info in 4-byte > > integers, for example. I suppose that using a derived type to > > ensure that in my implementation those fields conform with the > > original is one way to do it, but is that accepted practice, or > > is there a more usual one? > > =A0 Representation clauses and pragmas let you specify machine > characteristics, for instance that a particular field is 4 bytes long. > Types, and derived types, generally have to do with the logical nature of > the data > eg > type Field_Lengths is range 1 .. 64; > type Water_Temperatures is range 32 .. 212; > type Car_Mileages is range 0 .. 400_000; > etc > An item of any of those types would fit in a four byte field, even > though the first two types could fit in a single byte. =A0In the absence > of a representation clause, the compiler is allowed to choose whatever > it likes. =A0If you want something *represented* the same on two differen= t > machines, or via two different compilers, use representation clauses. ...but not necessarily on the types that you use in the application - that /can/ have a enormous performance hit. The compiler usually does a great job of picking the most optimal size for a type that it can. What you might then consider is deriving types with rep-clauses to, well, represent the structure you need to be portable (e.g. if it needs to go 'over a wire'). -- A type perhaps used a lot in an application type Internal is record I : Integer; B : Boolean; F : Float; end record; -- A required external representation but one that might have a large performance hit type External is new Internal; for External use record I at 0 range 0 .. 31; B at 1 range 0 .. 0; F at 2 range 0 .. 31; end record; procedure Write_To_Memory (My_Appliaction_Record : Internal) is My_Memory_Mapped_Record : Extenal; for My_Memory_Mapped_Record'Address use
; begin My_Memory_Mapped_Record :=3D External (My_Application_RecorD); end; And the compiler fills in the mapping. Note the reverse can be done as well. This technique work especially well with 'wholey' enums, e.g. -- Internal 'logical' representaion type Internal is (Alpha, Beta, Gamma); -- Required for an external interface type External in new Internal; for External ise (Alpha =3D> 1, Beta =3D> 2, Gamma =3D> 4); If the enumeration is being used to index into arrays a lot then you will see a big performance hit if you had added the rep-clause to the Internal type. Cheers -- Martin