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: kilgallen@eisner.decus.org (Larry Kilgallen) Subject: Re: Rules for Representation of Subtypes Date: 1996/09/26 Message-ID: <1996Sep26.191257.1@eisner>#1/1 X-Deja-AN: 185560545 x-nntp-posting-host: eisner.decus.org references: x-nntp-posting-user: KILGALLEN x-trace: 843779591/8293 organization: LJK Software newsgroups: comp.lang.ada Date: 1996-09-26T00:00:00+00:00 List-Id: In article , bobduff@world.std.com (Robert A Duff) writes: > 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. Like: if X'Valid ? I would think that as being an argument in _favor_ of declaring the C-updated object in a tightly constrained fashion. Larry Kilgallen