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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,571930b4ff0bc1ee X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-04-01 00:43:31 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.gv.tsc.tdk.com!news.iac.net!news-out.cwix.com!newsfeed.cwix.com!feed2.news.rcn.net!rcn!dispose.news.demon.net!demon!grolier!proxad.net!feeder2.proxad.net!nnrp6.proxad.net.POSTED!not-for-mail Message-ID: <3AC6E965.4C41542C@free.fr> From: Jean-Marc Bourguet X-Mailer: Mozilla 4.76 [en] (X11; U; SunOS 5.7 sun4u) X-Accept-Language: en, French, fr MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Compile time executed functions References: <3AC03CCE.70E3C2D5@mida.se> <3AC18DD1.EF25CE42@mida.se> <5mzw6.415$1H6.72722473@newssvr16.news.prodigy.com> <3AC2EB17.33AAEC0A@mida.se> <3AC46252.B7E54EA6@free.fr> <3AC4B7F9.7C73455A@free.fr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Sun, 01 Apr 2001 08:42:27 GMT NNTP-Posting-Host: 158.140.208.29 X-Complaints-To: abuse@proxad.net X-Trace: nnrp6.proxad.net 986114547 158.140.208.29 (Sun, 01 Apr 2001 10:42:27 CEST) NNTP-Posting-Date: Sun, 01 Apr 2001 10:42:27 CEST Organization: Guest of ProXad - France Xref: supernews.google.com comp.lang.ada:6311 Date: 2001-04-01T08:42:27+00:00 List-Id: Stephen Leake wrote: > > Jean-Marc Bourguet writes: > > > > : First feature, things like > > > : enum { foo = x+y*z; } > > > : are valid as long as x, y and z value are known at compile time and have > > > : to be evaluated at compile time. > > > > > > Isn't this usually resolvable as a constant by most Ada compilers? At least > > > the ones I know will usually do so. > > > > It is quite difficult to come with the equivalent in Ada. One is > > foo : constant = x+y*z; > > is indeed resolvable by most Ada compiler. > > Actually, since C and C++ define an enum to be just a named int, I don't know for C but for C++ an enum cary more type information that you seem to think. There is an implicit conversion from enum to int but not from int to an enum nor between enum. The following does not compile. enum E1 {a = 1, b = 2, c = 4}; enum E2 {d, e}; void f(E1 x); void g() { f(d); } because a E2 is passed where an E1 is expected. > this > is the _exact_ equivalent in Ada. I don't agree. > Perhaps you meant to say that [use of representation clause] > is not legal Ada. However, GNAT 3.14a disagrees with you. No. Using representation clause to try to emulate C++ enum value is doomed. The enum values are far more visible to the program. I think the more complete way to represent a C++ enum in Ada is use an integer type or an modular type with the correct range and give typed constant. Obviously the best way depend on the usage and may not be the more complete way... - Jean-Marc