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,8a019ea882aac73c X-Google-Attributes: gid103376,public From: Simon Wright Subject: Re: GNAT's internal format for Discriminant Records? Date: 1998/06/19 Message-ID: #1/1 X-Deja-AN: 364540387 X-NNTP-Posting-Host: pogner.demon.co.uk:158.152.70.98 References: <6meah3$3b$1@cronkite.sp.trw.com> X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 898372463 nnrp-05:19752 NO-IDENT pogner.demon.co.uk:158.152.70.98 Organization: At Home Newsgroups: comp.lang.ada Date: 1998-06-19T00:00:00+00:00 List-Id: "Rick Flower" writes: > We're trying to do some fixed format record layouts and are > looking into using discriminants.. These record formats will be > used to send data to hardware boxes, so the overhead of > what Ada might add when using some of the slick OO features > of the language are being checked into. Now, we've already > found that GNAT (3.10p under Solaris 2.6) adds the size of the > discriminant to the overall record size (i.e. if the discriminant is > 4 bits, then 4 bits are added to the overall record size). We > tried the same under GHS Adamulti (1.8.8D) and found that it > did NOT add that overhead. Now, for a few reasons, it would > appear that if there are multiple platforms/compilers involved > perhaps the use of discriminants should be avoided -- am I > correct in this theory? If your hardware target needs to know what sort of record you are passing to it then it must need the discriminant somehow? If not, you could check out the GNAT pragma Unchecked_Union (see the GNAT RM for 3.10): pragma Unchecked_Union (first_subtype_local_name) This pragma is used to declare that first_subtype_local_name should be equivalent to a C union type, and is intended only for use in interfacing with C code that uses union types. In Ada terms, the named type must obey the following rules: It is a non-tagged non-limited record type. It has a single discrete discriminant with a default value. The component list consists of a single variant part. Each variant has a component list with a single component. No nested variants are allowed. No component has an explicit default value. No component has a non-static constraint. In addition, given a type that meets the above requirements, the following restrictions apply to its use throughout the program: The discriminant name can be mentioned only in an aggregate. No subtypes may be created of this type. The type may not be constrained by giving a discriminant value. The type cannot be passed as the actual for a generic formal with a discriminant. [...]