Posted By

jimfred on 11/17/08


Tagged

file line stringize


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

khouser


print __FILE__ and __LINE__ using the # stringizing operator


 / Published in: C++
 

URL: http://www.decompile.com/cpp/faq/file_and_line_error_string.htm

Article explains why STRINGIFY and TOSTRING are both needed.

This technique is useful for embedded apps to print debug strings to a debug console. ASSERT or TRACE statements can incorporate these macros. The line numbers are converted to strings at compile-time rather than run-time.

  1. #define STRINGIFY(x) #x
  2. #define TOSTRING(x) STRINGIFY(x)
  3. #define AT __FILE__ ":" TOSTRING(__LINE__)
  4.  
  5. printf( AT " message"); // Expect output like: "snipplr.c:5 message"

Report this snippet  

You need to login to post a comment.