Re: Formatting a string on a variadic parameter function without using GC

2016-03-02 Thread David G. Maziero via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 05:04:37 UTC, David G. Maziero wrote: void RenderText( FontBMP font, int x, int y, const char* text, Just one more correction for future reference, RenderText should be extern(C) void RenderText... in order for it to work correctly with va_start/etc.

Re: Formatting a string on a variadic parameter function without using GC

2016-03-02 Thread David G. Maziero via Digitalmars-d-learn
On Wednesday, 2 March 2016 at 05:04:37 UTC, David G. Maziero wrote: char[256] buff; va_list ap; va_start( ap, text ); sprintf( buff.ptr, text, ap ); va_end( ap ); Sorry again, where it reads "sprintf" should be "vsprintf".

Re: Formatting a string on a variadic parameter function without using GC

2016-03-02 Thread David G. Maziero via Digitalmars-d-learn
I figured out what I wanted. Thanks for your answer Mike, sorry to bother you though. Here's the result: void RenderText( FontBMP font, int x, int y, const char* text, ... ) { SDL_Rect rect1, rect2; rect2.x = x; rect2.y = y; rect2.w = font.width;

Re: Formatting a string on a variadic parameter function without using GC

2016-03-02 Thread David G. Maziero via Digitalmars-d-learn
I forgot to add that the "RenderText(font,0,0,"FPS: "~to!string(fps));" was an older version where it wasn't const char *, but string. And I was using a foreach, so no null-termination. But that's beyond the point of not using GC.

Re: Formatting a string on a variadic parameter function without using GC

2016-03-02 Thread David G. Maziero via Digitalmars-d-learn
Yes, I'm aware of the null-termination thing. I might have pasted code that I already changed. But I already messed with sformat, and it seems that it does use the GC. I've put @nogc in RenderText, and the compiler says sformat uses GC, so I don't know. But the thing is, I don't want to

Formatting a string on a variadic parameter function without using GC

2016-03-02 Thread David G. Maziero via Digitalmars-d-learn
Hi. I think it's the first time I post here. I've been flirting with D for some time, but now I decided to start a little project. Consider the following function: void RenderText( FontBMP font, int x, int y, const char* text ) { SDL_Rect rect1, rect2; rect2.x = x;