Embed timestamp in object code at compile time with C++

后端 未结 7 918
梦谈多话
梦谈多话 2021-01-03 17:58

I want to perform a printf() to display when the currently executing code was last compiled. Does C/C++ provide a macro that gives you that resolves to a timest

7条回答
  •  误落风尘
    2021-01-03 18:24

    If you are using gcc preprocessor then you will find what you are looking for in the __TIME__ and __DATE__ macros

    Quotes from GNU C pre-processor documentation:

    __DATE__

    This macro expands to a string constant that describes the date on which the preprocessor is being run. The string constant contains eleven characters and looks like "Feb 12 1996". If the day of the month is less than 10, it is padded with a space on the left.

    ...

    __TIME__

    This macro expands to a string constant that describes the time at which the preprocessor is being run. The string constant contains eight characters and looks like "23:59:01".

提交回复
热议问题