How do I get the UTC offset for __TIME__?
We are using __TIME__
to embed the time of compilation in a binary. Unfortunately, a time without a UTC Offset is meaningless. I don't see an obvious way to get the timezone that the compiler is running in. I suppose I could grab this from the configure script. But is there a better way?
If I do it from a configure script, I'm going to need to put that into a .h or .c file somehow, and do somet开发者_如何学运维hing intelligent if the file is not there.
you can use compiler Flags to pass that externally. Most compiler provide '-D'
flag to define #define
macros externally. Let's suppose you put the UTC information in an environment variable. Pass that environment variable as -D
flag
set $myUTC="-7"
gcc -c mysource.cpp -DUTC=$myUTC
In your mysource.cpp
use the macro UTC
:
printf("Compiled at %d Offset %d", __TIME__, UTC);
精彩评论