formatted assert error messages inside nogc functions
Timothee Cour via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jan 10 00:45:24 PST 2016
update: with @nogc @trusted pure this becomes even uglier:
@nogc @trusted pure
void test(int a){
if(!(a==3)){
debug{
char[100]buf; //TODO:make sure big enough
// would like to use 'auto s=sformat(buf, "a = %s", a);' but not nogc:
https://issues.dlang.org/show_bug.cgi?id=13055
auto m=snprintf(buf.ptr, buf.length, "a = %d", a);
assert(m<buf.length && m>0);
assert(0, buf[0..m]);
}
else{
assert(0);
}
}
}
On Sat, Jan 9, 2016 at 11:54 PM, Timothee Cour <thelastmammoth at gmail.com>
wrote:
> Is there a better way than the example below to have an informative (ie
> formatted with runtime values) error message inside a nogc function?
>
> @nogc
> void test(int a){
> char[100]buf; //TODO:make sure big enough
> //auto s=sformat(buf, "a = %s", a);/// not nogc even though it accepts a
> buf
> auto m=snprintf(buf.ptr, buf.length, "a = %d", a);
> assert(m<buf.length && m>0);
> assert(a==3, buf[0..m]);
> }
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160110/921e23ee/attachment.html>
More information about the Digitalmars-d
mailing list