RE: ICU4C proposal: Formalizing the ustdio format specifiers
"Robert Buck" <[email protected]>
| Newsgroups | gmane.comp.lib.icu.general |
|---|---|
| Message-ID | <[email protected]> |
> -----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