www.digitalmars.com         C & C++   DMDScript  

D - preprocessor __FILE__ and __LINE__

From: http://www.digitalmars.com/d/pretod.html

	8.  	 Assert function file and line number information:

 The C Preprocessor Way
        #define assert(e)       ((e) || _assert(__LINE__, __FILE__))
My understanding is that in D there is no equivelant of __FILE__ or __LINE__ because assert has somthing like that built in. I am acustomed to using __FILE__ and __LINE__ in C to define a "log" macro that looks a bit like: #define log(severiry, message, ...) _log_real (__FILE__, __LINE__, severity, This lets me see where a log message comes from. I also have somthing like: #define my_assert(expr) (void){ if (!expr) _handle_assert(#expr, __FILE__, __LINE__) } .. then in _handle_assert I dump some state info and the assert mesasge into a file (and sometimes email it back to base from a customer site). I am impressed by D's attention to addressing quality issues (DBC, unit testing etc) but feel that the ability to have custom error handling and logging infrastructure with line file:line information is essential to ensuring quality. Will D provide some mechanism for building a customised assert in future? Sam
Apr 19 2004