Go Down

Topic: Displaying Date,time, and IDE/Compiler version in Serial Monitor (Read 30173 times) previous topic - next topic

cappy2112


I've gotten into the habit of manually adding the compile date & time to my project, so that
I can see when the project was built, using the Serial Monitor.

I'd also like to add the compiler version number to be displayed as well.

Do macros/functions exist to add the date, time, and compiler version into the code?
If so, would you please provide an example?

Thanks

Erdin

The compilation date and time can be written in a single string, and can also be placed in Flash.
I think that using the 'F()' macro requires different Serial.print() function calls.

Code: [Select]

// Example, not tested

// Combined string in RAM
Serial.println( "Compiled: " __DATE__ ", " __TIME__ ", " __VERSION__);

// The string in Flash
Serial.print( F("Compiled: ");
Serial.print( F(__DATE__));
Serial.print( F(", "));
Serial.print( F(__TIME__));
Serial.print( F(", "));
Serial.println( F(__VERSION__));


cappy2112


The compilation date and time can be written in a single string, and can also be placed in Flash.
I think that using the 'F()' macro requires different Serial.print() function calls.

Code: [Select]

// Example, not tested

// Combined string in RAM
Serial.println( "Compiled: " __DATE__ ", " __TIME__ ", " __VERSION__);

// The string in Flash
Serial.print( F("Compiled: ");
Serial.print( F(__DATE__));
Serial.print( F(", "));
Serial.print( F(__TIME__));
Serial.print( F(", "));
Serial.println( F(__VERSION__));




Thanks

This all works.
However, it's not easy to see at a glance which version of gcc is used with which version of the Arduino IDE.
I was hoping for a macro/function which will return the version of the Arduin IDE. ie 1.0.4, etc.

Thanks

Erdin

The define ARDUINO is 104 for version 1.0.4.
Serial.print(F( "Arduino IDE version: "));
Serial.println( ARDUINO, DEC);

MichaelMeissner



I've gotten into the habit of manually adding the compile date & time to my project, so that
I can see when the project was built, using the Serial Monitor.

I'd also like to add the compiler version number to be displayed as well.

Do macros/functions exist to add the date, time, and compiler version into the code?
If so, would you please provide an example?

Thanks

The ISO C/C++ standards mandate some special macros that are expanded as strings when used:

  • __DATE__ -- date of the compilation in the locale specific format

  • __TIME__ -- date of the compilation in the locale specific format

  • __FILE__ -- filename of the compiled file



GCC defines some other macros, specifically (note non-GCC compilers probably do not define these):

  • __VERSION__ -- compiler version as a string

  • __GNUC__ -- compiler major version number, i.e. for gcc 4.3.2, this would be 4

  • __GNUC_MINOR__ -- compiler minor version number, i.e. for gcc 4.3.2, this would be 3

  • __GNUC_PATCHLEVEL__ -- compiler patch level number, i.e. for gcc 4.3.2, this would be 2


cappy2112


The define ARDUINO is 104 for version 1.0.4.
Serial.print(F( "Arduino IDE version: "));
Serial.println( ARDUINO, DEC);


Thanks.

May I ask where this is documented?

cappy2112


The ISO C/C++ standards mandate some special macros that are expanded as strings when used:

  • __DATE__ -- date of the compilation in the locale specific format

  • __TIME__ -- date of the compilation in the locale specific format

  • __FILE__ -- filename of the compiled file



GCC defines some other macros, specifically (note non-GCC compilers probably do not define these):

  • __VERSION__ -- compiler version as a string

  • __GNUC__ -- compiler major version number, i.e. for gcc 4.3.2, this would be 4

  • __GNUC_MINOR__ -- compiler minor version number, i.e. for gcc 4.3.2, this would be 3

  • __GNUC_PATCHLEVEL__ -- compiler patch level number, i.e. for gcc 4.3.2, this would be 2




Thanks Michael

Go Up