Including compile timestamp in c?

Hello Back when I was doing assembler on the 8051, I used some compiler specific labels to include the date and time of compilation in a string. The microcontroller could then send out this information on request.

I hope this is the right NG for this question. I am now using Winavr and avr-gcc. I haven't done any coding in years.

How could I do this now?

Just to be specific, I am *not* asking for the Atmel to give me the _current_ date and time, I just want a string in flash with the compilation date and time of the code.

TIA

Reply to
a7yvm109gf5d1
Loading thread data ...

Most compilers provide the predifined macros __DATE__ and __TIME__ for that purpose.

--
Stef    (remove caps, dashes and .invalid from e-mail address to reply by mail)

In this world there are only two tragedies.  One is not getting what one
wants, and the other is getting it.
		-- Oscar Wilde
Reply to
Stef

#include int main(void) { printf("I was compiled on %s\n", __DATE__); return 0; }

Reply to
Chris Giese

I'm tickled pink by this, thanks. Was I searching for the wrong term, "timestamp"? This info didn't exactly pop out at me.

Reply to
a7yvm109gf5d1

Apparently!

Note #1: __TIME__ and __DATE__ are part of the ANSI C standard; while I'm sure there are compilers that don't support them, I haven't run into one.

Note #2: If you are interested in version control, one of the things that you want is for a 'production' build for a particular version of software to come out bit-exact each and every time. You want this, because five years down the road when some Very Important Customer wants Just One Change, or if you have to track down some Dread Bug, it is exceedingly soothing to be able to verify that you can, indeed, check out and rebuild some hex file that's going into production hardware.

This rules out using time and date stamping _on production builds_. My preferred process is to have a "version" header or source file that gets changed to match the version, and which takes a "development code" flag that tells it to insert compile time and date instead.

--
Tim Wescott
Control system and signal processing consulting
www.wescottdesign.com
Reply to
Tim Wescott

}

Yes time stamping the source files is better, but it is possible to do comparison scripts that check all but a small fixed set of bytes (those bytes being the time/date compiled). Had to do exactly that back in the late '80s.

So again: do it with source file dates (generated by your Source code controls system).

Ed

Reply to
Ed Prochak

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.