hidden passing of __FILE__ and __LINE__ into function

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 17 04:04:04 PDT 2017


On Monday, April 17, 2017 10:58:36 Basile B. via Digitalmars-d-learn wrote:
> On Monday, 17 April 2017 at 10:55:30 UTC, Jonathan M Davis wrote:
> > On Monday, April 17, 2017 10:30:35 Basile B. via
> >
> > Digitalmars-d-learn wrote:
> >> On Monday, 17 April 2017 at 10:22:47 UTC, Dmitry wrote:
> > void error(string msg, string file = __FILE__, size_t line =
> > __LINE__)
> > {
> >
> >     ...
> >
> > }
> >
> > That's what Exception's constructor does as well as functions
> > like std.exception.enforce.
> >
> > - Jonathan M Davis
>
> I didn't know that this also works for regular parameters. Then
> it's obviously better.

It doesn't in C++ (which is _really_ annoying), but it does in D. In C++,
it uses the file and line number of the declaration site, whereas in D, it
uses the file and line number of the call site.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list