S
santosh
Richard said:(e-mail address removed) said:
I don't see why it's advantageous to postpone until runtime a
calculation that can be performed trivially at compilation time.
Would it be as trivial for, say, a long double? I have had cases where
the same long double object produced an output of several lines of
digits for some values and just a few digits for others. Is there a
deterministic formula for doing this at compile-time based only on the
information derivable from float.h?
Ah, I think I understand what you thought I meant. You seem to think
that (given a C99 implementation to work with) I'm offering you three
choices:
(1a) snprintf twice
(1b) snprintf once
(1c) sprintf once
I wasn't. I was offering you *two* choices:
(2a) snprintf twice
(2b) snprintf once (to get the size), followed by buffer provision,
followed by sprintf
It is my contention that (2b) is superior to (2a).
How? 2b isn't any more portable than 2a, and it *might* be
infinitesimally faster. No data loss occurs in either case. So why is
2b superior to 2a?
It is my further contention that (2b) is not optimal, but we've
already had that fight, right?
Agreed.