CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

access to __DATE__ and __TIME__

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rolox



Joined: 25 Dec 2014
Posts: 33

View user's profile Send private message

access to __DATE__ and __TIME__
PostPosted: Sun Jan 25, 2015 5:00 pm     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 2:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 9:18 am     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 9:42 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group