full path to source file __FILE__

Jonathan Marler via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jul 22 12:28:05 PDT 2016


On Friday, 22 July 2016 at 19:13:31 UTC, sdhdfhed wrote:
> 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.

Actually I realized if __FILE__ was always absolute, then all 
your exception messages would contain the full path of the file 
it was thrown from on the machine it was compiled on. This would 
be quite odd. Both a relative and absolute version are useful in 
different cases.


More information about the Digitalmars-d-learn mailing list