[Cfp-interest] freestanding

Jim Thomas jaswthomas at sbcglobal.net
Sun Feb 26 15:20:59 PST 2012


On Feb 25, 2012, at 8:00 PM, Joel C. Salomon wrote:

> On 02/24/2012 11:33 AM, Jim Thomas wrote:
>> Feedback from the C committee urged the following changes to our draft
>> TS Part 1:
>> 
>>  * Allow freestanding implementations to conform. 
> <snip>
>> A key issue for the first one is avoiding the requirement for
>> freestanding implementations to support <stdlib.h> and <stdio.h>. Below
>> is a draft specification for a new header that provides the character
>> sequence conversion functionality required by IEEE 754. Please look it
>> over and send comments. I'd be particularly interested in hearing from
>> Joel, who first asked for this facility.
> <snip>
>> n          Floating-point string conversions <floatstr.h>
>> 
>> The header <floatstr.h> defines one type and five functions for
>> converting between floating types and decimal character sequences.
> 
> Looks good to me.  The simplicity of specification is a very strong
> argument in favor of what you've written.
> 
>> #include <floatstr.h>
>> int strfromd(char * restrict s, size_t n, const char * restrict format, double x);
>> int strfromld(char * restrict s, size_t n, const char * restrict format, long double x);
> 
> Might it be reasonable, for reasons of completeness, to also define
> strfromf, or does the lack of a float-specific format make this too
> confusing?
> 
> I could go either way on this, but if there is no strfromf, add a note
> that strfromd doubles as the IEEE 754-mandated
> single-precision-to-string operation. [pun intended]

An ideal specification of strfromf would convert float  to a character sequence directly, without first promoting x to double, as would happen with snprintf. The difference can show up in %a formatting. But such a specification would be a fair amount more complicated. I'm inclined to add strfromf, using the same snprintf definition as for the other two strfrom functions and noting the implicit promotion to double. If it becomes troublesome, we could easily remove it later. What do you think?

-Jim

> 
> [I assume it will be obvious to the Standards folks (though it took me a
> moment to recognize this) that you're suggesting strfromd rather than
> dtostr in order to keep to the reserved name-space.]
> 
> --Joel
> _______________________________________________
> Cfp-interest mailing list
> Cfp-interest at oakapple.net
> http://mailman.oakapple.net/mailman/listinfo/cfp-interest




More information about the Cfp-interest mailing list