comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: C Macros and their equivalent in Ada
Date: Tue, 9 Sep 2008 13:57:11 -0700 (PDT)
Date: 2008-09-09T13:57:11-07:00	[thread overview]
Message-ID: <11ad88c5-e158-4718-9fbd-cd3ba5a76627@l64g2000hse.googlegroups.com> (raw)
In-Reply-To: 90d69a98-ab81-45b2-bd0e-18675b327b66@d77g2000hsb.googlegroups.com

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



  reply	other threads:[~2008-09-09 20: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 [this message]
2008-09-10  6:57     ` Per Sandberg
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