Re: ICU4C proposal: Formalizing the ustdio format specifiers

"Mark Davis" <[email protected]>
Newsgroups gmane.comp.lib.icu.general
Message-ID <008e01c34713$cc686410$7900a8c0@DAVIS1>
I agree that we could promote (or for that matter demote) types in
printf.

However, one uses the same format string for printf and for scanf. In
scanf, the results are dumped into variables of the specified type,
with no error checking. If they are not the right type, bad things
happen.

Mark
__________________________________
http://www.macchiato.com
►  “Eppur si muove” ◄

----- Original Message ----- 
From: "Robert Buck" <[email protected]>
To: "Mark Davis" <[email protected]>; "George Rhoten"
<[email protected]>
Cc: <[email protected]>
Sent: Thursday, July 10, 2003 11:33
Subject: RE: ICU4C proposal: Formalizing the ustdio format specifiers




> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Mark
Davis
> Sent: Thursday, July 10, 2003 2:08 PM
> To: Robert Buck; George Rhoten
> Cc: [email protected]
> Subject: Re: ICU4C proposal: Formalizing the ustdio format
specifiers
>
>
> > - if the user specifies 'l' with d, i, or u, then do integral
> promotion to
> >   an int32_t, int32_t, or uint32_t.
> > - if the user specifies 'll' with d, i, or u, then do integrat
> promotion to
> >   an int64_t, int64_t, or uint64_t.
>
> We can't do this in scanf. It's got to be exactly the right type.

To say that means we aren't quite communicating clearly. Let me say it
another way.

If for instance I pass in a 'short' value as the subsequent argument
to format specifier of '%d', or '%ld', the internal code to your
implementation of scanf assigns the value to a int32_t. For each
format specifier there must be exactly one argument. The format
specifier maps to a particular type, chosen by platform convention.
The format-type and format-value are stored in a slot. The
format-value
I am presuming is stored in an opaque data type structure. The
format-type
indicates which method to use to retrieve the value later when
printing
it out. The retrieval of the value from the opaque data type structure
_may_ involve truncation or loss or misrepresentation of data [again,
mentioned elsewhere in the standard]. Hence what the standard says,
with my
interjections:

"... unsigned char argument (the argument will have been promoted
according to the integer promotions [to an internal type
whose size is sizeof(int)], but its value shall be converted to
signed char or unsigned char before printing); or that ..."

I am presuming your code first parses the format specifier to identify
the types involved, associates them to subsequent arguments in
'slots',
you then chain them in order of occurance, that the chain defines an
execution context of some sort, and for each slot in the context you
execute the appropriate functions, passing by reference the buffer to
which the functions are to write to.

Given this, what do you mean by "it's got to be exactly the right
type".

Bob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.