www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - __FILE__ and __LINE__ 'forwarding'

reply Lionello Lunesu <lio lunesu.remove.com> writes:
#void test(int i=__LINE__) { printf("%i",i);}
#void main() {
#  test(); // prints 1
#}

It would be really handy if the __LINE__ default parameter value would 
be evaluated at the line containing the call. This way we can mimic 
those C logging macros.

Is there currently any way to do this without writing __LINE__, __FUNC__ 
on every call?

L.
Sep 22 2006
next sibling parent Lutger <lutger.blijdestijn gmail.com> writes:
Lionello Lunesu wrote:
 #void test(int i=__LINE__) { printf("%i",i);}
 #void main() {
 #  test(); // prints 1
 #}
 
 It would be really handy if the __LINE__ default parameter value would 
 be evaluated at the line containing the call. This way we can mimic 
 those C logging macros.
 
 Is there currently any way to do this without writing __LINE__, __FUNC__ 
 on every call?
 
 L.

Indeed, this would be nice if possible. For the function name, I think this can be done with Don Clugston's meta library, meta.nameof should do the trick: "Given any D symbol (class, template, function, module name, or non-local variable) or any D type, convert it to a compile-time string literal, optionally containing the fully qualified and decorated name."
Sep 22 2006
prev sibling parent Juan Jose Comellas <jcomellas gmail.com> writes:
This feature would be great to have, especially when throwing Exceptions in
debug mode. Ideally, this should work for __FILE__, __LINE__ and __FUNC__.


Lionello Lunesu wrote:

 #void test(int i=__LINE__) { printf("%i",i);}
 #void main() {
 #  test(); // prints 1
 #}
 
 It would be really handy if the __LINE__ default parameter value would
 be evaluated at the line containing the call. This way we can mimic
 those C logging macros.
 
 Is there currently any way to do this without writing __LINE__, __FUNC__
 on every call?
 
 L.

Sep 22 2006