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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,1514d4f994aed7aa X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.belwue.de!th!lucks From: Stefan Lucks Newsgroups: comp.lang.ada Subject: Re: generic function and overloading Date: Thu, 18 Oct 2007 13:30:05 +0200 Organization: InterNetNews at News.BelWue.DE (Stuttgart, Germany) Message-ID: References: <1192688972.967825.31130@t8g2000prg.googlegroups.com> NNTP-Posting-Host: th.informatik.uni-mannheim.de Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: news.belwue.de 1192707008 6886 134.155.91.85 (18 Oct 2007 11:30:08 GMT) X-Complaints-To: news@news.belwue.de NNTP-Posting-Date: Thu, 18 Oct 2007 11:30:08 +0000 (UTC) In-Reply-To: <1192688972.967825.31130@t8g2000prg.googlegroups.com> Xref: g2news2.google.com comp.lang.ada:2482 Date: 2007-10-18T13:30:05+02:00 List-Id: > I have a few "hardware" types, for example uint16 and uint32. And I > want to write a functions that will set or clear bits of such types. > [...] I can define a generic Bit_Set, but then I have to > specialize it for uin16 and uint32 with different function names. I don't think so, see the example below: --begin example with Ada.Text_IO; procedure X is generic type Swap_Type is private; procedure Gen_Swap (X,Y: in out Swap_Type); procedure Gen_Swap (X,Y: in out Swap_Type) is Tmp: Swap_Type:= X; begin X := Y; Y := Tmp; end Gen_Swap; type U_Int_8 is mod 2**8; type U_Int_16 is mod 2**16; type U_Int_32 is mod 2**32; procedure Swap is new Gen_Swap(U_Int_8); procedure Swap is new Gen_Swap(U_Int_16); procedure Swap is new Gen_Swap(U_Int_32); I,J: U_Int_8 := 255; S,T: U_Int_16 := 255; begin J := J + 1; T := T + 1; Swap(I,J); Swap(S,T); if I >= J then Ada.Text_IO.Put_Line("Error for U_Int_8."); elsif S <= T then Ada.Text_IO.Put_Line("Error for U_Int_16."); else Ada.Text_IO.Put_Line("Everything fine, as expected!"); end if; end X; -- end example Now, if you change "Gen_Swap" into "Swap", you get an error message. Perhaps you got a similar error message and was puzzled by this. So long Stefan -- Stefan Lucks (moved to Bauhaus-University Weimar, Germany) ------ I love the taste of Cryptanalysis in the morning! ------