View previous topic :: View next topic |
Author |
Message |
rolox
Joined: 25 Dec 2014 Posts: 33
|
access to __DATE__ and __TIME__ |
Posted: Sun Jan 25, 2015 5:00 pm |
|
|
Hello,
I'm trying to use __DATE__ and __TIME__ to create a user defined version number at compile time
I need to create the Version number like f.e. "V150125.2215"
is there a way to access the single chars of the __DATE__ or __TIME__ ?
what i tried :
Code: | const char genVer1[] = __DATE__; |
works as expected, i get "25-Jan-15" in genVer1 in ROM
via defines :
Code: | #define BUILD_YEAR_CH0 (__DATE__[ 7])
#define BUILD_YEAR_CH1 (__DATE__[ 8]) |
gives no error at compile time, but
Code: | char test = BUILD_YEAR_CH0; |
is just zero :-(
Code: | const char genVer2[]={
'V',
__DATE__[7],
__DATE__[8],
'\0'
} |
gives just error "Expression must evaluate to a constant"
any tips ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon Jan 26, 2015 2:17 am |
|
|
No.
These are not arrays. They are text macro substitutions. When you type __DATE__ just as for a #defined value, the compiler substitutes the current date for this. You would have to put the date into a string, and then access this with standard C functions to build your target string. |
|
|
rolox
Joined: 25 Dec 2014 Posts: 33
|
|
Posted: Mon Jan 26, 2015 9:18 am |
|
|
Hello,
i thought of that - and works. Just wanted to save some ROM...
too bad that the compiler does just "something" with that defines without complaining |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Mon Jan 26, 2015 9:42 am |
|
|
Given that it is inside a text substitution, it is not actually a syntax error. Just doesn't do what you want....
Hence no error reported. |
|
|
|