January 10, 2016 Re: formatted assert error messages inside nogc functions | ||||
|---|---|---|---|---|
| ||||
Attachments:
| 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@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]);
> }
>
>
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply