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!news4.google.com!out02b.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!in03.usenetserver.com!news.usenetserver.com!pc02.usenetserver.com!news.flashnewsgroups.com-b7.4zTQh5tI3A!not-for-mail Newsgroups: comp.lang.ada Subject: Re: generic function and overloading References: <1192688972.967825.31130@t8g2000prg.googlegroups.com> From: Stephen Leake Date: Thu, 18 Oct 2007 07:07:33 -0400 Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/22.1 (windows-nt) Cancel-Lock: sha1:z4nujc9wMLS+cnLsrpS9l7sjLPI= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@flashnewsgroups.com Organization: FlashNewsgroups.com X-Trace: 9b8a747173e75e05e48ed32023 Xref: g2news2.google.com comp.lang.ada:2481 Date: 2007-10-18T07:07:33-04:00 List-Id: eliben writes: > I have a few "hardware" types, for example uint16 and uint32. You should use Interfaces.Unsigned_16 and Unsigned_32 for these. > And I want to write a functions that will set or clear bits of such > types. For example: > > function Bit_Set(word: uint16; bitn: natural) return uint16; > > function Bit_Set(word: uint16; bitn: natural) return uint16 is > mask: uint16 := 2**bitn; > begin > return word or mask; > end Bit_Set; Ok. > However, I realize that such a function would be almost completely > duplicated for the uint32 type. In C++ I would probably define it as a > template on the type of the word, and the compiler would do the job > for me. In Ada, however, when using generics it doesn't seem I can > leave the same function name for all types (as I would do in > overloading). I can define a generic Bit_Set, but then I have to > specialize it for uin16 and uint32 with different function names. Is > there any way I could combine the effects of generics and overloading > and get a single Bit_Set for all my types without writing the code N > times ? That should work as you describe. Can you show the code that doesn't work? Then we can help you fix it. > P.S. Ada95 This should work in Ada 83 :). Any reason you are not in Ada 2005 yet? -- -- Stephe