From: Per Sandberg <per.sandberg@bredband.net>
Subject: Re: C Macros and their equivalent in Ada
Date: Wed, 10 Sep 2008 06:57:39 +0000
Date: 2008-09-10T06:57:39+00:00 [thread overview]
Message-ID: <pxIxk.179783$W71.130835@newsfe12.ams2> (raw)
In-Reply-To: <11ad88c5-e158-4718-9fbd-cd3ba5a76627@l64g2000hse.googlegroups.com>
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 <ludo...@ludovic-brenta.org> 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
next prev parent reply other threads:[~2008-09-10 6:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-09 10:43 C Macros and their equivalent in Ada RasikaSrinivasan
2008-09-09 13:45 ` Colin Paul Gloster
2008-09-09 16:33 ` Ray Blaak
2008-09-09 18:54 ` RasikaSrinivasan
2008-09-10 0:16 ` Ray Blaak
2008-09-09 14:11 ` Jeffrey R. Carter
2008-09-09 14:39 ` Ludovic Brenta
2008-09-09 20:57 ` Maciej Sobczak
2008-09-10 6:57 ` Per Sandberg [this message]
2008-09-10 19:22 ` Keith Thompson
2008-09-09 15:11 ` Adam Beneschan
2008-09-13 3:33 ` Steve
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox