faking a C logging macro

BCS BCS_member at pathlink.com
Thu Apr 20 14:45:10 PDT 2006


Tydr Schnubbis wrote:
> Can I get something like this in D, using mixins or whatever?
> 
> #define log(s) logprintf(__FILE__ ": " __FUNCTION__ ": %s", s)


sed "/log\(/logprintf(__FILE__ `: ` __FUNCTION__ `: %s`, /" in.d -o out.d

???

No but seriously folks, I have wanted something like this a few times myself. 
Particularly, some way to get the __FILE__, etc. set of constants of the line 
where a template is instanced. Something like the following would be great.



template log(
   char[] s,
   char[] fi = __FILE__,
   int li = __LINE__,
   char[] fn = __FUNCTION__)  // const defaults come from called location
{
	const char[] log = ...
}


main.d
int i;
void main()
{
	pragma(msg, log!("this is broken!!!");
}



compile time output:
main.d:4 this is broken!!!





More information about the Digitalmars-d-learn mailing list