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,FREEMAIL_FROM, INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e9442435fdfe0d3d,start X-Google-Attributes: gid103376,public From: johnherro@aol.com (John Herro) Subject: Re: Generic Packages Date: 1996/03/22 Message-ID: <4iugrr$r4h@newsbf02.news.aol.com>#1/1 X-Deja-AN: 143726237 sender: root@newsbf02.news.aol.com references: <4inq3c$lr9@NNTP.MsState.Edu> organization: America Online, Inc. (1-800-827-6364) newsgroups: comp.lang.ada Date: 1996-03-22T00:00:00+00:00 List-Id: vkire@ERC.MsState.Edu (Kiril Nikola Vidimce) writes: > ... I was wondering was if I could define a generic > package with a generic constant/value that would > be passed when instantiating the package. Inside a generic package, generic formal parameters are treated as constants in any case. The following example, which works in Ada 83 and Ada 95, instantiates a generic package with a constant: generic Number : Integer; package P is procedure Show; end P; with Text_IO; package body P is procedure Show is begin Text_IO.Put_Line(Integer'Image(Number)); end Show; end P; with P; procedure Test is I : constant Integer := 3; package P3 is new P(Number => I); begin P3.Show; end Test; As expected, the program displays 3, and if you attempt to add the line Number := Number + 1; to procedure Show in the body of P, the compiler will reject the statement as an assignment to a read-only object. However, that's still true even if you remove the word constant from the line I : constant Integer := 3; in procedure Test. The generic formal parameter is treated as a constant in any case. For this reason you can't declare generic Number : constant Integer; package P is ... > I am very new in Ada ... You've come to the right place! I hope this helps. Good luck learning and using Ada; you'll like it! - John Herro Software Innovations Technology http://members.aol.com/AdaTutor ftp://members.aol.com/AdaTutor