full path to source file __FILE__

sdhdfhed via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 22 12:13:31 PDT 2016


On Friday, 22 July 2016 at 14:02:03 UTC, Jonathan Marler wrote:
> The __FILE__ trait seems to be used most useful for error 
> messages.

Another usage is for testing parsers or string functions directly 
on the source. E.g in "devel" mode the main function

void main(string[] args)
{
     version(devel)
     {
         // dont mess with params, use the text in source to catch 
most simple bugs.
         File f = File(__FILE__, "r");
     }
     else
     {
         // load using args
     }
}

> I could see him wanting it to be a relative path sometimes and 
> an absolute one other times.  By redefining it to always be 
> absolute would solve this problem,

I'm for this, always absolute. Eventually forced by a new switch: 
default behavior is not changed.




More information about the Digitalmars-d-learn mailing list