Re: [AD] usprintf()

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Sorry for my late reply.

Shawn Hargreaves wrote:
> Sven Sandberg <ssven.geo@xxxxxxxxxx> writes:
> > Other bugs are that it sometimes prints a negative sign before zero
> 
> Really? I wonder how on earth it manages that!

I think it is in cases like when -0.0004711 is printed with only two
decimals precision. Avoiding this seems like quite a complicated thing
to implement, but djgpp's libc does it cleanly.

> But I don't have especially strong feelings either way. I tend not to 
> print out floating point numbers very often, hence my not bothering to 
> implement exponential formats for them (one of the harder things). 

The reason why I found these missing features was that I needed
exponential form, but my whole string consists of only one floating
point number so I can just use libc's routine and then convert it into
unicode. Perhaps floating point numbers aren't used that often in games,
so if no one else needs it, it could maybe be reasonable to leave it
out. But maybe the docs should mention it?

[snip]
>    printf("%(%s%d)s", name, score, "Player %1 got %2 points");
[snip]
> Does anyone see a use for this? I found it very handy in XG2, but it's 
> of course not at all standard, and I tend to think that people might 
> just not use it. Is it worth adding?

This looks like a really cool system, though personally I don't think I
would use it very much: I tend to not translate my programs at all,
since I would only be able to do it properly into Swedish and that
wouldn't affect most users anyway (that is, if anyone would ever use my
programs:o). But as soon as commercial people start using Allegro, I
imagine they might find it very useful. And it can't hurt to add it,
because it is completely backwards compatible. I would say, throw it in
if you already have the code! Or alternatively, it could perhaps be made
as an addon?

Vincent Penquerc'h wrote:
> On Mon, Jan 17, 2000 at 11:06:22PM +0100, Grzegorz Adam Hankiewicz 
> wrote:
> > >    printf("%(%s%d)s", name, score, "Player %1 got %2 points");
> > How do you have to do this stack check? I have never dealt with 
> > stacks before, so I don't know what to do/where to look.
> 
> probably with stdarg features. You must have the same number of % in 
> the first string (except the first enclosing one) and the second one. 
> You then parse the first string to know the sizes of the arguments 
> passed, like a regular printf style routine.

I thought Shawn meant that no matter how stupid the translator is, he
can never cause stack overwriting by accidentally changing a % character
because when %3 occurs you will always know if 3 is greater than the
number of arguments given by the programmer. But the programmer who
writes the first format string will always have the chance to do things
wrong by not passing the same arguments as he says he does; I don't
think there is any way to prevent that (the stdarg features don't know
where the stack ends, neither do they know what types the variables on
the stack have).


I also attach my patch to make big floats not be clamped to INT_MAX.

Sven

Attachment: usprintf.zip
Description: Zip archive



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/