Proposal for new compiler built-ins: __CTX__ and __CONTEXT__

Paul Backus snarwin at gmail.com
Fri Jun 23 15:43:04 UTC 2023


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.


More information about the Digitalmars-d mailing list