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,a65079927bff9697 X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: 'Digit in generic package Date: 1996/08/27 Message-ID: #1/1 X-Deja-AN: 176803615 references: <9608261530.AA06035@most> organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.ada Date: 1996-08-27T00:00:00+00:00 List-Id: In article <9608261530.AA06035@most> "W. Wesley Groleau (Wes)" writes: > At least one vendor supplied a generic math package that did exactly > that AND on examining the disassembled code for an instantiation, we > found that the compiler had looked at the parameters and eliminated > the "dead code" so that the effect was exactly what Mr. O'Keefe had > asked for. This is what you should expect in some--but not all--cases. > Now I wonder whether in Ada 95 it would work to simplify R. Eachus's > suggestion with > ... > function Generic_F ... is > Precision : constant := Max(Foo'Digits,Bar'Digits,...); > begin > case Precision is ... Make that: Precision : constant := Integer'Max(Foo'Digits,Bar'Digits); ...and the compiler should accept it if, and only if, all (sub)type names are static. This requires both static bounds, an that the type not be a generic formal parameter. (The initialization expression for Precision must be static both in the generic and the instance.) If you say instead: Precision: constant Integer := Integer'Max(Foo'Digits,Bar'Digits); then Precision can be static in the instance even though it is not static in the generic template. This is exactly the behavior commented on above. And if an instance is such that some code can be statically eliminated, most compilers will do so. (There is at least one compiler on the market which uses a generic model which prevents this, but that is an accepted trade-off. By not doing any generic instantiations at compile time, the resulting code size is smaller.) Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is... -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...