a predefined compile-timestamp token? 
Author Message
 a predefined compile-timestamp token?

Hi all,
I want to put a compile date/time stamp in the help-page output of
my ANSI-C program, like "This program was last compiled on...".
I was expecting to find some pre-defined token like COMPILETIME (or
something) in one of the libraries, but I don't see one.  I also
haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
to update a timestamp definition in a separate header file, but
that seems silly.  There must be something akin to the token I
mentioned...  Anyone done this elegantly before?
TIA, -Andy
--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?
Try the __DATE__ and __TIME__ predefined macros.  They each give a
string literal that gives the date and time when the compilation
of the current source file began.  They are a part of ANSI C; I'm not
100% sure if there are part of K&R C, but believe they are.

Quote:

> Hi all,
> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  I also
> haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
> c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
> to update a timestamp definition in a separate header file, but
> that seems silly.  There must be something akin to the token I
> mentioned...  Anyone done this elegantly before?
> TIA, -Andy

-<Automagically included trailer>
Robert O'Dowd                       Ph    +61 (8) 9553 3618
DSTO Bldg A51                       Fax    +61 (8) 9553 3577
HMAS Stirling                       Email:

Rockingham, Western Australia, 6958

Disclaimer: Opinions above are mine and may be worth what you paid for
them
--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?
How about trying the predefined macros __DATE__ & __TIME__

--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?


Quote:
>Hi all,
>I want to put a compile date/time stamp in the help-page output of
>my ANSI-C program, like "This program was last compiled on...".
>I was expecting to find some pre-defined token like COMPILETIME (or
>something) in one of the libraries, but I don't see one.  I also
>haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
>c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
>to update a timestamp definition in a separate header file, but
>that seems silly.  There must be something akin to the token I
>mentioned...  Anyone done this elegantly before?
>TIA, -Andy

Check the predefined macros provided by ISO C.  __DATE__ and __TIME__
provide the resource you need.

Francis Glassborow      Chair of Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA          +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?

Quote:

> Hi all,
> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  

Try __DATE__ and __TIME__.

void compile_time( FILE *fout )
{
    fprintf( fout,
             "This program was rebuilt at %s, %s\n",
           __TIME__, __DATE__ );

Quote:
}

--
########################################################################

Emmenjay Consulting Pty Ltd             http://www.zip.com.au/~emmenjay/

Computers *ARE* user-friendly.  You just need to be properly introduced.
--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?

Quote:

> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  I also
> haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
> c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
> to update a timestamp definition in a separate header file, but
> that seems silly.  There must be something akin to the token I
> mentioned...  Anyone done this elegantly before?

__DATE__ and __TIME__ are ANSI C.

That gets you "This file was last compiled on...".  File, not program.
And compiled, not linked.

What do people do for "This program was last linked on..."?  

I put __DATE__ into a separate little stub function in a separate
file, and make that file dependent on every other file in my makefile.
It works, but is there a more elegant solution?
--

--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?

How about:

printf("<Compiled at %s on %s>\n",__TIME__,__DATE__);


  Andy> Hi all, I want to put a compile date/time stamp in the
  Andy> help-page output of my ANSI-C program, like "This program was
  Andy> last compiled on...".  I was expecting to find some
  Andy> pre-defined token like COMPILETIME (or something) in one of
  Andy> the libraries, but I don't see one.  I also haven't found it
  Andy> discussed anywhere in K&R, Summit's FAQ, c.l.c., or c.l.c.m.
  Andy> In the meantime, I've been using a shell-call in my makefile
  Andy> to update a timestamp definition in a separate header file,
  Andy> but that seems silly.  There must be something akin to the
  Andy> token I mentioned...  Anyone done this elegantly before?  TIA,

--
Peter Gieser, Ph.D.         Phone: (352) 392-5198  #306
POG Statistical Office      FAX:   (352) 392-8162

Gainesville, FL 32601       Web:   www.stat.ufl.edu/personnel/faculty.html

             * Send me email to receive my PGP public key *
--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?
Only thing I can suggest is try __TIMESTAMP__

Mitch



Quote:
> Hi all,
> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  I also
> haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
> c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
> to update a timestamp definition in a separate header file, but
> that seems silly.  There must be something akin to the token I
> mentioned...  Anyone done this elegantly before?
> TIA, -Andy
> --


--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?

Quote:

> Hi all,
> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".

Try __DATE__ and __TIME__.

--
Eric Amick
Columbia, MD

--



Sat, 21 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?

Quote:

> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  I also
> haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
> c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
> to update a timestamp definition in a separate header file, but
> that seems silly.  There must be something akin to the token I
> mentioned...  Anyone done this elegantly before?

You could always use the predefined macros __DATE__, __FILE__, and
__TIME__

Oh, btw, you'd have definitely found the answer in the standard itself
or in Harbison and Steele's "C: A Reference Manual", 4th Edition.

--
 { Sunil Rao }
"And India acquired yet another willing convert to the philosophy of
 the meaningfully meaningless...  Or was it the meaninglessly
 meaningful?  Did anyone know what was happening?"  --  Gita Mehta
--



Tue, 24 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?


Quote:
> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  I also

ANSI C (6.8.8) has the predefined constants  __DATE__ and __TIME__ for
that purpose. RTFM ;-)

Greetings from
 _____
 /_|__| Auke Reitsma, Delft, The Netherlands.
/  | \  -------------------------------------
        Remove NO_SPAM_ from my address ...
--



Tue, 24 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?

Quote:

> Hi all,
> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  I also
> haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
> c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
> to update a timestamp definition in a separate header file, but
> that seems silly.  There must be something akin to the token I
> mentioned...  Anyone done this elegantly before?
> TIA, -Andy

Use the __DATE__ and __TIME__ macros.  (Note:  Each begins and ends with
*two* underscores.)  They expand to character string literals giving
respectively the "date of translation of the source file" (formatted as
Mmm dd yyyy, although the first 'd' is a blank for days 1..9) and the
"time of translation of the source file" (formatted hh:mm:ss).

Reference:  The ANSI(ISO) C Standard, section 6.8.8.

Pedantry:  The Standard contains some caveats warning that the date and
time may not be available but in general, they are.

--
James M. Stern                Northrop Grumman Corp.  Hawthorne, CA
Opinions expressed above are not necessarily my employer's.
--



Tue, 24 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?

Quote:

> Hi all,
> I want to put a compile date/time stamp in the help-page output of
> my ANSI-C program, like "This program was last compiled on...".
> I was expecting to find some pre-defined token like COMPILETIME (or
> something) in one of the libraries, but I don't see one.  I also
> haven't found it discussed anywhere in K&R, Summit's FAQ, c.l.c., or
> c.l.c.m.  In the meantime, I've been using a shell-call in my makefile
> to update a timestamp definition in a separate header file, but
> that seems silly.  There must be something akin to the token I
> mentioned...  Anyone done this elegantly before?
> TIA, -Andy

Use the __DATE__ and __TIME__ macros.  (Note:  Each begins and ends with
*two* underscores.)  They expand to character string literals giving
respectively the "date of translation of the source file" (formatted as
Mmm dd yyyy, although the first 'd' is a blank for days 1..9) and the
"time of translation of the source file" (formatted hh:mm:ss).

Reference:  The ANSI(ISO) C Standard, section 6.8.8.

Pedantry:  The Standard contains some caveats warning that the date and
time may not be available but in general, they are.

--
James M. Stern                Northrop Grumman Corp.  Hawthorne, CA
Opinions expressed above are not necessarily my employer's.
--



Tue, 24 Apr 2001 03:00:00 GMT  
 a predefined compile-timestamp token?


Quote:
> What do people do for "This program was last linked on..."?  

I'd use something like this:

build_id.h:

extern const char build_id[];

Makefile:

final_binary: whatever it depends on
        echo "const char build_id[] = \"`date`\";" > build_id.c
        <call compiler for build_id.c>
        <call linker>

This, of course, requires that the development environment provides
a way to execute arbitrary commands to build something. I've given
an example for make because it is very widespread. If you cannot use
basic shell features like command substitution (this `date` thing)
because you're using DOS or a similar system, you can write a C
program for this task:

create_build_id_c: create_build_id.c
        <call compiler>

final_binary: create_build_id_c whatever it depends on
        <call create_build_id_c to create build_id.c>
        <call compiler for build_id.c>
        <call linker>

The Linux kernel, as another example, keeps a counter in the file
$(srcdir)/.version that is incremented each time a build process is
started. It becomes part of the kernel version id (together with
kernel version number, build machine name and current date and time).

--
Jan
--



Tue, 24 Apr 2001 03:00:00 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. cpp predefined tokens indicating OS/version

2. C program compiled-timestamp question...

3. token pasting without matching tokens

4. What is differences between predefined _WIN32 and WIN32?

5. predefined macros

6. predefined define in ansi C

7. Predefined macro __DATE__

8. predefined macro etc

9. C99: predefined macros: curious: hosted implementation (?)

10. printing to a predefined form

11. Predefined macro for __FUNCTION__ name?

12. predefined variables off ansi-c

 

 
Powered by phpBB® Forum Software