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,f0aecf9351d714ac X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!lightspeed.eweka.nl!213.239.142.3.MISMATCH!feed.xsnews.nl!border-2.ams.xsnews.nl!eweka.nl!hq-usenetpeers.eweka.nl!69.16.177.246.MISMATCH!cyclone03.ams.highwinds-media.com!news.highwinds-media.com!npeersf02.ams.highwinds-media.com!newsfe12.ams2.POSTED!40385e62!not-for-mail From: Per Sandberg User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: C Macros and their equivalent in Ada References: <90d69a98-ab81-45b2-bd0e-18675b327b66@d77g2000hsb.googlegroups.com> <11ad88c5-e158-4718-9fbd-cd3ba5a76627@l64g2000hse.googlegroups.com> In-Reply-To: <11ad88c5-e158-4718-9fbd-cd3ba5a76627@l64g2000hse.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@WWWSpace.NET NNTP-Posting-Date: Wed, 10 Sep 2008 05:02:13 UTC Date: Wed, 10 Sep 2008 06:57:39 +0000 Xref: g2news2.google.com comp.lang.ada:7696 Date: 2008-09-10T06:57:39+00:00 List-Id: If using GNAT the simple approach for those two macros could be found in the package: GNAT.Source_Info where you could find: function File return String; -- Current file function Line return Positive; -- Current Line function Source_Location return String; -- Current file & Line function Enclosing_Entity return String; -- Enclosing name. /Per Maciej Sobczak wrote: > On 9 Wrz, 16:39, Ludovic Brenta wrote: > >> If you need that feature, you're better off generating an Ada source >> file from the "date" utility, e.g. >> >> echo "package Compilation_Date is" > compilation_date.ads >> echo " Timestamp : constant String := \"$(date --full-ISO)\";" >> >> compilation_date.ads >> echo "end Compilation_Date;" >> compilation_date.ads > > This is a simple and valid approach but works only for things that are > build-wide. > The other extremely useful macros from the C world are __FILE__ and > __LINE__. I'm afraid there is no way to simulate them using any > external solutions, short of using the real preprocessor (why not?). > > Yeah - why not use the cpp preprocessor? > > Let's say that instead of implementing the .adb file we write > something that will be used to generate it: > > $ cat a.adbs > with Ada.Text_IO; > procedure A is > begin > Ada.Text_IO.Put_Line (__DATE__ & " " & __TIME__); > end A; > $ cpp -P a.adbs > a.adb > $ gnatmake a > gcc -c a.adb > gnatbind -x a.ali > gnatlink a.ali > $ ./a > Sep 9 2008 22:53:23 > $ > > Works for me. I can even write a rule in Makefile to make (pun > intended) that automated. Not sure if GNAT project files can do it, > though. > > -- > Maciej Sobczak * www.msobczak.com * www.inspirel.com > > Database Access Library for Ada: www.inspirel.com/soci-ada