Special Token __FUNCTION__

Robert Jacques sandford at jhu.edu
Mon Sep 7 10:03:58 PDT 2009


On Mon, 07 Sep 2009 12:41:46 -0400, Byron Heads <wyverex.cypher at gmail.com>  
wrote:

> I've looked through the lex documents but there seems to be no special  
> token
> to get the current calling function.
>
> In c you can use the __func__ token to get the current function.
>
> I thinking adding __FUNCTION__ would be useful for things like logging.
>
> Also is there a nice way to replace logging macros?  I often have a  
> logger
> that looks like
> logmsg( int level, uint line, char* func, char* file, char[] msg, ... );
>
> then I would write some macros like:
> #define LOGDEBUG( m, ... )  logmsg( LVL_DEBUG, __LINE__, __func__,  
> __FILE__, msg, __VA_ARGS__ )
>
> thus i would only have to do
> LOGDEBUG( "SOME STRING with formatting", formatting args.. )
>
> -B

You can put __LINE__, etc into template parameters. For example:

void echo(int T = __LINE__, U...)(U msg) { writeln(T,": ",msg); }



More information about the Digitalmars-d mailing list