Macro to identify File and Function name

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smitap
    New Member
    • Oct 2006
    • 2

    Macro to identify File and Function name

    Hi ,

    I have to print the name of the file and the function into a log file. I am using "writeToLog " function for that in all the files and all the functions in that file.
    Can anyone let me know about a macro which can be used for this purpose so that the same line of code is written in all the files and functions instead of changing the function name and file name for all the occurrances of writeToLog().
    A code snippet for the same will be highly useful.
    Thanks
    Smita
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    There are 2 Standard C Predefined macros that could help you

    __FILE__ The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks.

    __LINE__ The line number in the current source file. The line number is a decimal integer constant. It can be altered with a #line directive.

    Code:
    printf("File: %s Line %d\n", __FILE__, __LINE__);
    There is no standard macro to get the current function name. However I recently saw an extention in a compiler that provided one so check your toolset documentation.

    Comment

    Working...