Is there any hope for "lazy" and @nogc?

Mike Franklin slavo5150 at yahoo.com
Tue Jul 31 07:29:53 UTC 2018


On Tuesday, 31 July 2018 at 07:17:34 UTC, Shachar Shemesh wrote:
> I'm trying to figure out what's the signature of the built-in 
> assert. It does not seem that I can define a similar function 
> myself.
>
> Help??
>

I'm not sure why you want a different assert, but you can 
consider these options.

1) Assign your own assert handler:  
https://github.com/dlang/druntime/blob/52d3fe02272d16d32c150ce6f78bc00241a9dd5d/src/core/exception.d#L393

2) You can provide your own implementations of the runtime hooks 
at 
https://github.com/dlang/druntime/blob/cb5efa9854775c5a72acd6870083b16e5ebba369/src/core/exception.d#L628

extern(C) void _d_assertp(immutable(char)* file, uint line)
{
     import core.stdc.stdio;
     printf("Houston, we have a problem at %s:%u\n", file, line);
}

void main()
{
     assert(false);
}

https://run.dlang.io/is/QZEO9W

3) -betterC seems to forward runtime assertions to the C 
implementation.  See https://run.dlang.io/is/QZEO9W

For that you have to provide a new implementation of `__assert`:

extern(C) void __assert(const char *msg, const char *file, int 
line)
{
     import core.stdc.stdio;
     printf("Houston, we have a problem at %s:%u\n", file, line);
}

extern(C) void main()
{
     assert(false);
}

https://run.dlang.io/is/D5JxCT

4) Otherwise can't you just implement two `myAssert` overloads?

`void assert(bool condition, string msg);`
`void assert(bool condition)`

Please clarify if I'm missing the point.

Mike


More information about the Digitalmars-d mailing list