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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,571930b4ff0bc1ee,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-26 23:16:53 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!news.tele.dk!194.213.69.151!news.algonet.se!algonet!pepsi.tninet.se!not-for-mail From: Mats Karlssohn Newsgroups: comp.lang.ada Subject: Compile time executed functions Date: Tue, 27 Mar 2001 09:10:06 +0200 Organization: MIDA Systemutveckling AB Message-ID: <3AC03CCE.70E3C2D5@mida.se> NNTP-Posting-Host: sdu16-244.ppp.algonet.se Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: cubacola.tninet.se 985677031 2546 195.163.244.16 (27 Mar 2001 07:10:31 GMT) X-Complaints-To: abuse@algo.net NNTP-Posting-Date: 27 Mar 2001 07:10:31 GMT X-Mailer: Mozilla 4.6 [en] (WinNT; I) X-Accept-Language: en Xref: supernews.google.com comp.lang.ada:6101 Date: 2001-03-27T07:10:31+00:00 List-Id: After following the thread on C style preprocessing, an old wish of mine popped up in my brain (or whatever is inside the scull :). Sometimes, especially when doing embedded programming, I feel a great need to execute a function to get literal initialization a constant. That is I'd like to have the compiler to execute a function for me (at compiletime!) and use the return of that function to initialize the constant. Example (pleas, this is just an example, it hasn't been compiled): type Byte is mod 2**8; type Word is mod 2**16; type CRC_Lookup_Table is array(0..255) of Byte; constant CRC_Polynom := 4711; -- replace with a 'correct' polunom function Generate_CRC_Table(Polynom : in Word) return CRC_Lookup_Table is begin -- Implementation end Generate_CRC_Table; package Package_Using_CRC is constant CRC_Lookup_Table := Generate_CRC_Table(CRC16_Polynom); -- end Package_Using_CRC; - The constant is really a constant an should therefore be placed in ROM. - Therefore the function Generate_CRC_Table isn't needed in the output at all and since it may be quite large and/or time consuming it would be nice to do the job once, at compile time. The way I'm currently doing this is by building a small external program that generates an appropriate code fragment, that gets pasted into the right place. This gives both maintenance and configuration management headaches. I must admit that I havn't researched enough to say that I can't get the same effect using generice and/or other techniques in Ada. Now, first I wonder have somebody out there solved this issue in a way that complies with the first to points above ? I realize that a lot of limitations must be put on the Generate_CRC_Table function, but, have something along these lines been considered by the language designers. I have hoped to get the time to either build a small preprocessor to do this kind of execution/substitution trick, or to add the same trick into GNAT using some pragma(Compiler_Executed, func). Sorry to say, I don't see that ammount of time in the near future. Finally, as usual, I beg you to bear with my english. -- Mats Karlssohn, developer mailto:mats@mida.se Mida Systemutveckling AB http://www.mida.se Box 64, S-732 22 ARBOGA, SWEDEN Phone: +46-(0)589-89808 Fax: +46-(0)589-89809