comp.lang.ada
 help / color / mirror / Atom feed
* C Macros and their equivalent in Ada
@ 2008-09-09 10:43 RasikaSrinivasan
  2008-09-09 13:45 ` Colin Paul Gloster
                   ` (4 more replies)
  0 siblings, 5 replies; 12+ messages in thread
From: RasikaSrinivasan @ 2008-09-09 10:43 UTC (permalink / raw)


are there Ada equivalents of the C macros like :

__DATE__, __TIME__

My searches have not revealed anything. have i missed any obvious
pragmas?

thanks, srini



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  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 14:11 ` Jeffrey R. Carter
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 12+ messages in thread
From: Colin Paul Gloster @ 2008-09-09 13:45 UTC (permalink / raw)


On Tue, 9 Sep 2008, RasikaSrinivasan@gmail.com wrote:

|-----------------------------------------------------------------|
|"are there Ada equivalents of the C macros like :                |
|                                                                 |
|__DATE__, __TIME__                                               |
|                                                                 |
|My searches have not revealed anything. have i missed any obvious|
|pragmas?"                                                        |
|-----------------------------------------------------------------|

How about the function
Ada.Calendar.Clock
to get the current instant and passing that to the Date parameter of
the Ada.Calendar.Split procedure (such that the date would be output
to the other parameters)?

Similarly you could use / and mod to get the time of day from
Ada.Calendar.Seconds.

See
WWW.AdaIC.org/standards/05rm/html/RM-9-6.html#I3741
.

Regards,
Colin Paul Gloster



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 10:43 C Macros and their equivalent in Ada RasikaSrinivasan
  2008-09-09 13:45 ` Colin Paul Gloster
@ 2008-09-09 14:11 ` Jeffrey R. Carter
  2008-09-09 14:39 ` Ludovic Brenta
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 12+ messages in thread
From: Jeffrey R. Carter @ 2008-09-09 14:11 UTC (permalink / raw)


RasikaSrinivasan@gmail.com wrote:
> are there Ada equivalents of the C macros like :
> 
> __DATE__, __TIME__

I have no idea. Perhaps if you told us what you are trying to achieve, rather 
than how you achieved it in some other language we may not know, you would get a 
more useful reply.

-- 
Jeff Carter
"When danger reared its ugly head, he bravely
turned his tail and fled."
Monty Python and the Holy Grail
60



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 10:43 C Macros and their equivalent in Ada RasikaSrinivasan
  2008-09-09 13:45 ` Colin Paul Gloster
  2008-09-09 14:11 ` Jeffrey R. Carter
@ 2008-09-09 14:39 ` Ludovic Brenta
  2008-09-09 20:57   ` Maciej Sobczak
  2008-09-09 15:11 ` Adam Beneschan
  2008-09-13  3:33 ` Steve
  4 siblings, 1 reply; 12+ messages in thread
From: Ludovic Brenta @ 2008-09-09 14:39 UTC (permalink / raw)


RasikaSrinivasan@gmail.com wrote:
> are there Ada equivalents of the C macros like :
>
> __DATE__, __TIME__
>
> My searches have not revealed anything. have i missed any obvious
> pragmas?

No, Ada does not have macros. I am not aware of any compiler that
provides the equivalent of C's __DATE__ and __TIME__ macros (which,
for those here who don't know C, expand to the date and time at which
preprocessing took place, as strings).

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

HTH

--
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 10:43 C Macros and their equivalent in Ada RasikaSrinivasan
                   ` (2 preceding siblings ...)
  2008-09-09 14:39 ` Ludovic Brenta
@ 2008-09-09 15:11 ` Adam Beneschan
  2008-09-13  3:33 ` Steve
  4 siblings, 0 replies; 12+ messages in thread
From: Adam Beneschan @ 2008-09-09 15:11 UTC (permalink / raw)


On Sep 9, 3:43 am, "RasikaSriniva...@gmail.com"
<RasikaSriniva...@gmail.com> wrote:
> are there Ada equivalents of the C macros like :
>
> __DATE__, __TIME__
>
> My searches have not revealed anything. have i missed any obvious
> pragmas?
>
> thanks, srini

Ada doesn't have a standard mechanism for providing the compilation
date and time.  There's no reason why a particular implementation
couldn't provide something like this, though---perhaps a package with
special String constants or functions (most likely using pragma
Import) that would cause the compiler to substitute the compile date/
time when the constant or function is used.  Our compiler has
something like this.  Don't know whether GNAT does.  If you need it,
you may want to ask your compiler vendor for this sort of feature.  It
shouldn't be terribly difficult to implement.

                                  -- Adam



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 13:45 ` Colin Paul Gloster
@ 2008-09-09 16:33   ` Ray Blaak
  2008-09-09 18:54     ` RasikaSrinivasan
  0 siblings, 1 reply; 12+ messages in thread
From: Ray Blaak @ 2008-09-09 16:33 UTC (permalink / raw)


Colin Paul Gloster <Colin_Paul_Gloster@ACM.org> writes:
> On Tue, 9 Sep 2008, RasikaSrinivasan@gmail.com wrote:
> |"are there Ada equivalents of the C macros like :                |
> |                                                                 |
> |__DATE__, __TIME__                                               |
>
> How about the function Ada.Calendar.Clock to get the current instant

The idea is to get the date/time the file was compiled.

Rasika, what I have often done is generate a source file from my build script
that has the version and build dates baked in. E.g. using ant:

  <property name="VERSION" value="1.1"/>

  <target name="generate.version">
    <tstamp>
      <format property="yyyyMMdd" pattern="yyyyMMdd"/>
    </tstamp>
    <echo file="src/Support/Version.adb">
package body Version is

  function Version return String is
  begin
    return "${VERSION}";
  end;

  function Build return String is
  begin
    return "${yyyyMMdd}";
  end;
end;
    </echo>
  </target>

Apologies for any errors, but it should get the idea across.

-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
rAYblaaK@STRIPCAPStelus.net                    The Rhythm has my soul.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 16:33   ` Ray Blaak
@ 2008-09-09 18:54     ` RasikaSrinivasan
  2008-09-10  0:16       ` Ray Blaak
  0 siblings, 1 reply; 12+ messages in thread
From: RasikaSrinivasan @ 2008-09-09 18:54 UTC (permalink / raw)


I have a similar solution implemented. thanks. was just trying to
figure out if there was anything recent.


On Sep 9, 12:33 pm, Ray Blaak <rAYbl...@STRIPCAPStelus.net> wrote:
> Colin Paul Gloster <Colin_Paul_Glos...@ACM.org> writes:
>
> > On Tue, 9 Sep 2008, RasikaSriniva...@gmail.com wrote:
> > |"are there Ada equivalents of the C macros like :                |
> > |                                                                 |
> > |__DATE__, __TIME__                                               |
>
> > How about the function Ada.Calendar.Clock to get the current instant
>
> The idea is to get the date/time the file was compiled.
>
> Rasika, what I have often done is generate a source file from my build script
> that has the version and build dates baked in. E.g. using ant:
>
>   <property name="VERSION" value="1.1"/>
>
>   <target name="generate.version">
>     <tstamp>
>       <format property="yyyyMMdd" pattern="yyyyMMdd"/>
>     </tstamp>
>     <echo file="src/Support/Version.adb">
> package body Version is
>
>   function Version return String is
>   begin
>     return "${VERSION}";
>   end;
>
>   function Build return String is
>   begin
>     return "${yyyyMMdd}";
>   end;
> end;
>     </echo>
>   </target>
>
> Apologies for any errors, but it should get the idea across.
>
> --
> Cheers,                                        The Rhythm is around me,
>                                                The Rhythm has control.
> Ray Blaak                                      The Rhythm is inside me,
> rAYbl...@STRIPCAPStelus.net                    The Rhythm has my soul.




^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 14:39 ` Ludovic Brenta
@ 2008-09-09 20:57   ` Maciej Sobczak
  2008-09-10  6:57     ` Per Sandberg
  2008-09-10 19:22     ` Keith Thompson
  0 siblings, 2 replies; 12+ messages in thread
From: Maciej Sobczak @ 2008-09-09 20:57 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 18:54     ` RasikaSrinivasan
@ 2008-09-10  0:16       ` Ray Blaak
  0 siblings, 0 replies; 12+ messages in thread
From: Ray Blaak @ 2008-09-10  0:16 UTC (permalink / raw)


"RasikaSrinivasan@gmail.com" <RasikaSrinivasan@gmail.com> writes:
> I have a similar solution implemented. thanks. was just trying to
> figure out if there was anything recent.

I would argue that generating the version file explicitly from a build script
is actually superior to __DATE__/__TIME__ macros, since the actual compilation
build time is often inconsistent.

If the version file has not actually changed in a while, for example, typical
build environments just use the last object file, meaning the datestamps can
be quite obsolete and thus inaccurate.

By tying it to the build script, you can do things like saying "make a
official release NOW", and know that the version datestamp is tied to that
explicit action.

This is important to allow one to correlate the datestamp to changelongs,
release notes, etc.
-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
rAYblaaK@STRIPCAPStelus.net                    The Rhythm has my soul.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 20:57   ` Maciej Sobczak
@ 2008-09-10  6:57     ` Per Sandberg
  2008-09-10 19:22     ` Keith Thompson
  1 sibling, 0 replies; 12+ messages in thread
From: Per Sandberg @ 2008-09-10  6:57 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 20:57   ` Maciej Sobczak
  2008-09-10  6:57     ` Per Sandberg
@ 2008-09-10 19:22     ` Keith Thompson
  1 sibling, 0 replies; 12+ messages in thread
From: Keith Thompson @ 2008-09-10 19:22 UTC (permalink / raw)


Maciej Sobczak <see.my.homepage@gmail.com> writes:
[...]
> 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?
[...]

The cpp preprocessor is designed to be used with C and C++.

For example, the apostrophe character in C, if it appears outside a
string literal, is used only as a delimiter for a character constant.
If you have a single apostrophe on a line because you're using an Ada
qualified expression or attribute, or even in an Ada comment (the
leading -- will be treated as an operator symbol), then cpp is likely
to complain or even terminate.

One implementation I just tried issued a warning message and continued
processing, but that's not guaranteed.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: C Macros and their equivalent in Ada
  2008-09-09 10:43 C Macros and their equivalent in Ada RasikaSrinivasan
                   ` (3 preceding siblings ...)
  2008-09-09 15:11 ` Adam Beneschan
@ 2008-09-13  3:33 ` Steve
  4 siblings, 0 replies; 12+ messages in thread
From: Steve @ 2008-09-13  3:33 UTC (permalink / raw)


<RasikaSrinivasan@gmail.com> wrote in message 
news:f0560361-31c2-4a3d-851c-639cdfc5ac46@i76g2000hsf.googlegroups.com...
> are there Ada equivalents of the C macros like :
>
> __DATE__, __TIME__
>
> My searches have not revealed anything. have i missed any obvious
> pragmas?
>
> thanks, srini

Years ago I was looking for exactly the same thing on a Windows target.  So 
far as I could find, Ada doesn't have a standard way of accessing this 
information.

The reason I was looking for the information is so that a program could 
report when it was built.

I found an alternative that works on Windows.  There is a windows API 
function GetFileVersionInfo that may be used to obtain the date and time the 
executable was linked.

If this happens to be what you're looking for, let me know and I can send 
(or post) source code.

Regards,
Steve





^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-09-13  3:33 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2008-09-10 19:22     ` Keith Thompson
2008-09-09 15:11 ` Adam Beneschan
2008-09-13  3:33 ` Steve

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox