C/C++ line number
As part of the C++ standard there exists some pre-defined macros that you can use. Section 16.8 of the C++ standard defines amongst other things, the __LINE__
macro.
__LINE__
: The line number of the current source line (a decimal constant).__FILE__
: The presumed name of the source file (a character string literal).__DATE__
: The date of translation of the source file (a character string literal...)__TIME__
: The time of translation of the source file (a character string literal...)__STDC__
: Whether__STDC__
is predefined__cplusplus
: The name__cplusplus
is defined to the value 199711L when compiling a C ++ translation unit
So your code would be:
if(!Logical)
printf("Not logical value at line number %d \n",__LINE__);
You should use the preprocessor macro __LINE__
and __FILE__
. They are predefined macros and part of the C/C++ standard. During preprocessing, they are replaced respectively by a constant string holding an integer representing the current line number and by the current file name.
Others preprocessor variables :
__func__
: function name (this is part of C99, not all C++ compilers support it)__DATE__
: a string of form "Mmm dd yyyy"__TIME__
: a string of form "hh:mm:ss"
Your code will be :
if(!Logical)
printf("Not logical value at line number %d in file %s\n", __LINE__, __FILE__);