__DIR__ trait (return getcwd at compile time), replacing __FILE_FULL_PATH__

Timothee Cour via Digitalmars-d digitalmars-d at puremagic.com
Mon Jan 9 09:47:27 PST 2017


__FILE_FULL_PATH__ is broken (doesn't work with optional parameters):
https://issues.dlang.org/show_bug.cgi?id=16640
Although this bug should be fixed, I think there's something better:

How about introduce instead a __DIR__ trait which is equal to the absolute
path of current directory during compilation.

Advantages:

* no need to change function signatures:

void fun(int arg0, string file=__FILE__, int line=__LINE__){
  enum file_full_path=buildPath(__DIR__, file);
  // file_full_path can be used at compile time if needed
}

instead of changing to:
void fun(int arg0, string file= __FILE_FULL_PATH__, int line=__LINE__){ ...}


* more flexible: we can have both __FILE__ and it's absolute version

* smaller binaries (no need to store redundant path information in
__FILE_FULL_PATH__ when __DIR__ + __FILE__ is enough)

__FILE_FULL_PATH__ can be put in deprecation path

NOTE: there is areal use case for having a full path available [see see
associated discussion in pull https://github.com/dlang/dmd/pull/5959], the
one proposed here (__DIR__) is less intrusive: function signature doesn't
change, but implementation can add __DIR__ to get absolute path when needed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20170109/fcbae039/attachment.html>


More information about the Digitalmars-d mailing list