Re: Printf question.



On 2005-12-31, Malcolm <regniztar@xxxxxxxxxxxxxx> wrote:
> "Flash Gordon" <spam@xxxxxxxxxxxxxxxxxx> wrote
>>
>>> Correction: since a signed int can hold any value of type unsigned
>>> char, the value in the unsigned char 'a' is promoted to type int.
>>
>> <annoying pedant>
>> What, even on a system with CHAR_BIT==16 and sizeof(int)==1 ?
>> </annoying pedant>
>>
>> Of course, you are only likely to find such systems in the embedded world
>> where you may well not have printf.
>>
> But often you have vsprintf(), or you need to implement it.
>
> The whole language does begin to break down when we push the limits of
> ANSI's definition. For instance, should field-length parameters really be
> size_t s?

You could take the cheap way out and do stuff along the lines of

sprintf(format,"%%%d.%df",width,precision>=0?precision:0);

c89 doesn't appear to provide for field-length parameters anyway - at
least the draft i have doesn't.
.



Relevant Pages

  • Re: Should embedded systems compilers be trusted
    ... C89 4.11.6.1 The memset Function ... For each of the signed integer types, ... And doesn't C99 guarantee that unsigned char will have no padding bits ...
    (comp.lang.c)
  • Re: ANNOUNCE: Leopard10 CSPRNG
    ... I mention C89 because the exitfunction is defined by that standard. ... L10ByteType is typedef'd as an unsigned char. ...
    (sci.crypt)
  • Re: Void Main?
    ... It does, so does C89. ... This is what i infer out of the "It shall be ... but it's reliant on implementation-defined behavior. ... unsigned char *x; ...
    (comp.lang.c)
  • Re: Unsigned Integers and Fortran
    ... I don't know how to do the same thing as simply in fortran as in C. ... Note that even in C actually working with unsigned char ... the actual operations are normally done as int. ... in a function call would have type int. ...
    (comp.lang.fortran)