formatted assert error messages inside nogc functions

Timothee Cour via Digitalmars-d digitalmars-d at puremagic.com
Sat Jan 9 23:54:17 PST 2016


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/20160109/c94c007a/attachment.html>


More information about the Digitalmars-d mailing list