compile information into static array

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

compile information into static array

615 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gonzalo_Sipel on Wed Aug 20 06:48:40 MST 2014
Hello,
I was wondering if there is any way to store or save some code information into my compiled code. I would like to use date of compilation to initialize a constant variable. Is there any macro which allow me to do that? I'm looking for a way to save automatically date of compilation or code version to be able to show it in my LCD device.
Thanks.
0 项奖励
回复
2 回复数

602 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gonzalo_Sipel on Thu Aug 21 04:29:51 MST 2014
rocketdawg,
                    Thank you for the information,I found it very useful!
0 项奖励
回复

602 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rocketdawg on Wed Aug 20 11:37:28 MST 2014
The C language has such a construct.
it is called "const"
it is considered good form to declare the type T and then add the modifier "const"
T const variableName

unsigned int const LCDVersion = 5;
unsigned char const Title[] = "Greatest Application";
similar to these are the __DATE__, __TIME__, __FUNCTION__, __FILE__, __LINE__, ...
these are pre-processor defines in GCC.  If you are using another compiler, you will have to check that they work.
printf("%s\n", __DATE__);

so something like
unsigned char const BuildDate[] = __DATE__;  // might work for you, if I have the types correct

Dan Saks http://www.dansaks.com/articles.htm has some useful articles about const.
also see http://www.embedded.com/




0 项奖励
回复