Proposal for new compiler built-ins: __CTX__ and __CONTEXT__
ryuukk_
ryuukk.dev at gmail.com
Fri Jun 23 18:16:11 UTC 2023
On Friday, 23 June 2023 at 15:43:04 UTC, Paul Backus wrote:
> On Friday, 23 June 2023 at 14:39:36 UTC, ryuukk_ wrote:
>> ```D
>> void infoStack(string msg) {
>> enum ctx = __traits(context);
>> writefln("%s(%s): %s", ctx.file, ctx.line, msg);
>> }
>> ```
>
> Suppose I put this function in a module by itself and compile
> it. What code should the compiler generate?
>
> Because D is an AoT-compiled language, and functions may be
> called from multiple contexts, the only way for a function to
> know its calling context is for that information to be passed
> to it from the call site.
Oh that's a good point, i didn't thought of that, thanks
More information about the Digitalmars-d
mailing list