預處理器常用變量

The following are preprocessor variables and part of the C/C++ standard. During preprocessing, they are replaced respectively by a constant string  or a  integer .

  • '__DATE__'                 -> a string literal of the form "Mmm dd yyyy"
  • '__TIME__'                   -> a string literal of the form "hh:mm:ss"
  • '__TIMESTAMP__'     -> a string literal of the form "Mmm dd yyyy hh:mm:ss"
  • '__FUNCTION__'        -> a string literal which contains the function name (this is part of C99, the new C standard and not all C++ compilers support it)
  • '__FILE__'                   ->  a string literal holding the current file name
  • '__LINE__'                   ->  a integer representing the current line number.

在程序中可以直接使用這些宏。

例如:

printf("Filename:%10s  Line: %s ",__FILE__,__LINE__);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章