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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,878cc452376823e0 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!news.motzarella.org!motzarella.org!not-for-mail From: =?ISO-8859-1?Q?S=E9bastien?= Newsgroups: comp.lang.ada Subject: Re: Generic body Date: Thu, 15 May 2008 09:25:12 +0000 Organization: A noiseless patient Spider Message-ID: <482C0178.5020501@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: feeder.motzarella.org U2FsdGVkX1+hjaAEMPVj1NOkwJbj/ZDlDLxaAJUXRKlB9DFv7Av5yde3YYEDgKhKDan9tzvKPhKEydOc+4J3C2iMNhams9N9PTBLLk9FMo1r0PMulQvOmEJYlqbUJMTmeuHZSwi2srJmXphJV5/mrg== X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers NNTP-Posting-Date: Thu, 15 May 2008 09:23:16 +0000 (UTC) In-Reply-To: X-Auth-Sender: U2FsdGVkX19M4Z4ZHt9A8eEjpVBMxuE/gk/W8ghaI3Ts2A5DuQlBEA== Cancel-Lock: sha1:CfdDwt2SiYfiOMw0rphJH8U3zAc= User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) Xref: g2news1.google.com comp.lang.ada:71 Date: 2008-05-15T09:25:12+00:00 List-Id: > somewhere in it. But if you really need the ability to use "String" > here, do this in your generic: > > type Toto(<>) is limited private; > > I realize this has nothing to do with your question. Not but it's an interesting issue. I remembered this syntax I saw some places and then read that: http://en.wikibooks.org/wiki/Ada_Programming/Generics#Generic_formal_types Now I understand well the matter. Thanks. > Regarding your question: you really can't do this in Ada, because of > 3.11(13-14): "For the instantiation of a generic unit that has a body, > a check is made that this body is already elaborated....The exception > Program_Error is raised if any of these checks fails." The compiler > *should* accept your program with no errors, but it should fail at > runtime because the program will have to "elaborate" the generic > instantiation before it elaborates the generic body, and the program > will fail on Program_Error before it even gets started. If your > compiler is rejecting your program, then either it is doing so because > it "knows" that the program can't possibly work when it runs, or it > has a bug. > Although there may be ways to suppress the elaboration check, > depending on your compiler, I wouldn't take that approach, because the > check is there for a reason. If you suppress the check, there's a > possibility that your program may not work as expected, depending on > what the body of your generic looks like, especially if it refers to > any global variables in the body of MyPack. Yes I understand that warning are now a good things in Ada :-) Espcially when it says some exceptions will be raised at runtime. So I take time to undestand and correct any warning. > I'd recommend putting the generic in its own library unit, or in a > different package: > > package MyProcPack is -- I hate this name > generic > type Toto(<>) is limited private; > procedure MyProc; > end MyProcPack; > > package body MyProcPack is > procedure MyProc is ... end MyProc; > end MyProcPack; > > with MyProcPack; > pragma Elaborate_All (MyProcPack); > package MyPack is > procedure MyProcInt is new MyProcPack.MyProc(Toto => Integer); > procedure MyProcStr is new MyProcPack.MyProc(Toto => String); > end MyPack; > > The Elaborate_All pragma is necessary to ensure that the body of > MyProcPack (including the body of the generic MyProc) is elaborated > before MyProc is instantiated. > > If you don't understand what elaboration is all about, it's too > difficult to explain here---sorry. But just trust me that you'll need > to do something like what I'm recommending. I read a lot of stuff about elaboration, I'm not a master of the subject yet, but I understand a bit about it. I thought that Elaborate_All was about dynamic check vs static check? (flat -gnatE for circular dependancy) >> I don't how to do this because: >> 1) The compiler refuse the instance of MyProc because it doesn't have >> the MyProc body > > As I've mentioned, the compiler really shouldn't refuse this, because > it's a legal Ada program although it cannot work right. Some > compilers have modes that cause them to reject programs that are > certain to raise predefined exceptions, even when the programs are > legal, and your compiler could be running in a mode like this. > >> 2) If I put the body of MyProc in the package spec, the compiler refuses >> it because it's not the right place. > > Right---you can't put any sort of body in a package spec. Ok thanks to all of you for your help. Sebastien