Oh optimist! You would not expect one standard to pay attention to another, would you? The definition of __TIMESTAMP__ does not conform to the C standard, as you know. It would be great to have a format like your proposed __TIMESTAMP_ISO__ (would you always like Zulu time, or would it be better to have a local time zone offset?), But frankly, the easiest way to add it could be a patch for GCC and Clang, etc. .d.
You can try the monkey with asctime() , as suggested by user1034749 , d rather don't try this.
In the GCC 4.8.1 manual , there is an interesting warning:
-Wno-builtin-macro-redefined
Do not warn if certain built-in macros are overridden. This suppresses warnings for overriding __TIMESTAMP__ , __TIME__ , __DATE__ , __FILE__ and __BASE_FILE__ .
This allows you to try:
gcc ... -Wno-builtin-macro-redefined -D__TIMESTAMP__=$(date +'"%Y-%m-%dT%H:%M:%S"') ...
(Note the hieroglyphs needed to get a string from date , surrounded by double quotes.) However, some earlier versions of GCC do not support this option; I do not remember that it was before. You can override __TIMESTAMP__ :
$ gcc -std=c99 -Wall -Wextra -O xx.c -o xx $ ./xx Fri Jul 5 19:56:25 2013 $ gcc -std=c99 -Wall -Wextra -D__TIMESTAMP__=$(date +'"%Y-%m-%dT%H:%M:%S"') -O xx.c -o xx <command-line>: warning: "__TIMESTAMP__" redefined $ ./xx 2013-07-05T20:10:28 $
Not very pretty, but it works ... Oh, and for the record only, the source code was (trivial):
#include <stdio.h> int main(void) { printf("%s\n", __TIMESTAMP__); return 0; }
Jonathan leffler
source share