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,45a9122ddf5fcf5 X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Rules for Representation of Subtypes Date: 1996/09/26 Message-ID: #1/1 X-Deja-AN: 185469840 references: organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-09-26T00:00:00+00:00 List-Id: In article , Matthew Heaney wrote: >You say "generally" be represented the same way: can you be more specific? >Under what circumstances can they be different? Well, aliased Strings could be different sizes, for example. >BTW: Why doesn't Ada have a 'Storage_Size clause for (non-access) types or >objects? It should. >Here's another question: > > type T is new Interfaces.Integer_32 range 0 .. 255; > >What is the size of T? Do I need to specify a size clause to ensure that >objects of type T are 4 bytes? Yes. But this is all very obscure. If you're interfacing to hardware, or to C, or to something else where the interface is a low-level binary interface, the best thing to do is make the types match the hardware, or the C, or whatever it is. Don't use constraints on the Ada side of the interface, just because the logical properties would warrant a constraint. For example, suppose you call a C function that takes a pointer to an int, and the function updates the pointed-to int. The documentation promises that the value will always be in 1..10. DO NOT say "type T is range 1..10;", or "subtype T is Interfaces.C.int range 1..10;" on the Ada side. Because, if the documentation lies, your program will be erroneous. If, on the other hand, you use Interfaces.C.int, at the interface, and *then* assign it into a constrained thing, you will get a Constraint_Error for the bad data. Or, you can write an "if" statement to check for bad data. - Bob