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 01:00:05 PST Path: supernews.google.com!sn-xit-03!supernews.com!freenix!fr.usenet-edu.net!usenet-edu.net!proxad.net!feeder2.proxad.net!nnrp6.proxad.net.POSTED!not-for-mail Message-ID: <3AC6ED5F.9F2F51A5@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:59:21 GMT NNTP-Posting-Host: 158.140.208.29 X-Complaints-To: abuse@proxad.net X-Trace: nnrp6.proxad.net 986115561 158.140.208.29 (Sun, 01 Apr 2001 10:59:21 CEST) NNTP-Posting-Date: Sun, 01 Apr 2001 10:59:21 CEST Organization: Guest of ProXad - France Xref: supernews.google.com comp.lang.ada:6312 Date: 2001-04-01T08:59:21+00:00 List-Id: Ken Garlington wrote: > > "Jean-Marc Bourguet" wrote in message > news:3AC4B7F9.7C73455A@free.fr... > : Ken Garlington wrote: > : > > : > "Jean-Marc Bourguet" wrote in message > : > news:3AC46252.B7E54EA6@free.fr... > : > : Ken Garlington wrote: > : > : > : > : > Could you post an example of such a template, and what in the C++ > : > standard > : > : > you rely upon to guarantee compile-time calculations? > : > : > : > : 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. > : > : > More to the point, does the C++ standard _require_ that foo not generate > any > : > assembly instructions to be executed at run-time? If so, what does it > say? > : > : I've not checked what the standard says precisely. The enum values are > : a compile time constant. They may be used in context like case label > : which are to be fixed at compile time. This > : > : enum { a = 2, b = 3, c = 4, d = 7 }; > : enum { foo = a+b*c }; > : enum { bar = a*d }; > : > : void f() { > : int foobar; > : switch(foobar) { > : case foo: > : break; > : case bar: > : break; > : } > : } > : > : is required to produce a diagnostic as foo and bar have the same value. > > Same with Ada, as far as I know. I'm totally unable to come with an equivalent in Ada. There is no anonymous enum types, here you have three, the equivalent of the case labels are constrained to be of the same types, here the value on which one switch is of one type and the two labels of two different types,... > These examples are all in terms of "the value has to be calculated as a > scalar before it is used." This is *not* the same as saying "no code is > generated at run-time". I think there are NO requirement about generated code excepted the observable behavior for conforming program. Everybody would be surprised that the generated code for the factorial template I gave produced something other than what is generated for int main() { std::cout << 3628800 << std::endl; } -- Jean-Marc