Displaying Date,time, and IDE/Compiler version in Serial Monitor

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 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.

// 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__));

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.

// 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

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

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

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

Erdin:
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?

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