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.7 required=5.0 tests=BAYES_00,MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,ea6e62e15bb000fc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-01-26 11:50:44 PST From: Ted Dennison Newsgroups: comp.lang.ada Subject: Re: Source code preprocessing ? Date: Fri, 26 Jan 2001 19:40:57 GMT Organization: Deja.com Message-ID: <94sjs6$9en$1@nnrp1.deja.com> References: <3A6D87AD.66EE0AF@loria.fr> <94k90a$v1n$1@nnrp1.deja.com> <3A71B72E.5BC97054@loria.fr> NNTP-Posting-Host: 204.48.27.130 X-Article-Creation-Date: Fri Jan 26 19:40:57 2001 GMT X-Http-User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; 0.7) Gecko/20010109 X-Http-Proxy: 1.0 x61.deja.com:80 (Squid/1.1.22) for client 204.48.27.130 X-MyDeja-Info: XMYDJUIDtedennison Path: supernews.google.com!sn-xit-02!supernews.com!bignews.mediaways.net!stueberl.r-kom.de!news.csl-gmbh.net!newsfeed01.sul.t-online.de!newsfeed00.sul.t-online.de!t-online.de!grolier!btnet-peer0!btnet-peer!btnet!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail Xref: supernews.google.com comp.lang.ada:4571 Date: 2001-01-26T19:40:57+00:00 List-Id: In article <3A71B72E.5BC97054@loria.fr>, Xavier HILAIRE wrote: > Thank you for your answer. Meantime, I realized the problem of porting > my #ifdefs was readily solved in Ada thanks to genericity. As a single > example, > in C++ I have : > > #ifdef WANT_ABRITARY_PRECISION > > typedef cl_R Rational; > typedef cl_I Integer; > > #else > > typedef long long double Rational; > typedef long long int Integer; > > #endif You are talking about passing the actual type of Rational into a generic as an instantiation parameter, right? I don't think that really solves your problem, so much as it moves it around a little. You still have to have some code somewhere that instantiates that type with "cl_R" or "long long double" depending on some condition. Sure, you could put that in a source file with a version for each platform (to be chosen by the build system). But then what have you gained over just doing that for the type without using the generic? > I presume using a generic type in Ada is not enough, because one can > never know if equality between elements makes sense or not, especially > the compiler. But using a generic package *and* a boolean value > indicating whether or not equality on rationals make sense or not > should solve it (am I right ?) First off, in Ada "=" (and ":=") exists for every type (excepting those defined as "limited"). This includes records and arrays. Ada is a *real* language, not some toy like C. :-) Secondly, in a generic this issue is typically handled by one of the following methods: If the actual type to be supplied is unknown in composition, but can be a record or scalar (or private type), then the formal parameter should be defined as "private". This means that the generic can assume that "=" is available (among other things). If the actual type to be supplied could be a "limited" type (for which "=" is *not* available), then the formal should be defined as "limited private". This means that the "=" function will not be available (assignment won't be available either). If "=" must be available, but the user might want to use a custom equality (for instance, you might want to dereference a pointer in the object and compare the contents rather than the pointers), then a formal parameter for the "=" function for that type may be added to the generic's formal parameters. The instantiating code can supply any function with the same parameter profile as the actual and it will be used for "=" within the generic. -- T.E.D. http://www.telepath.com/~dennison/Ted/TED.html Sent via Deja.com http://www.deja.com/