wint_t is not the promoted version of wchar_tThis issue has been automatically converted from the original issue lists and some formatting may not have been preserved.
Authors: Clive D.W. Feather <clive@demon.net>, UK C Panel
Date: 2001-09-07
Submitted against: C99
Status: Fixed
Fixed in: C99 TC2
Converted from: summary-c99.htm, dr_270.htm
In the fprintf conversion specifier "%lc", the corresponding argument is of
type wint_t, but is then treated as if it contained a wchar_t value. In
7.19.6.1#18, the last call is:
fprintf(stdout, "|%13lc|\n", wstr[5]);
This argument has the type wchar_t.
There is no requirement in the Standard that the default argument promotions
convert wchar_t to wint_t. Therefore this example exhibits undefined
behaviour on some implementations. Nonetheless, the code looks like it ought to
work, and WG14 should consider changing the definition of wint_t to force it.
The current definition of wint_t is in 7.24.1#2:
wint_twhich is an integer type unchanged by default argument promotions that can hold any value corresponding to members of the extended character set, as well as at least one value that does not correspond to any member of the extended character set (see
WEOFbelow);269) and269
wchar_tandwint_tcan be the same integer type.
Three possible solutions are:
wint_t to be the promoted version of wchar_t.%lc to take promoted wchar_t rather than wint_t.Change the quoted line of 7.19.6.1#18 to:
fprintf(stdout, "|%13lc|\n", (wint_t) wstr[5]);
Change the cited portion of 7.24.1#2 to:
wint_twhich is the integer type resulting when the default argument promotions are applied to the typewchar_t;269) and
[Italics are used to show the changed text.]
Change 7.19.6.1#7 and 7.24.2.1#7, l modifier, to:
l(ell)Specifies that a following d,i,o,u,x, orXconversion specifier applies to along intorunsigned long intargument; that a followingnconversion specifier applies to a pointer to along intargument; that a followingcconversion specifier applies to an argument whose type is that resulting when the default argument conversions are applied to the typewchar_t; that a followingsconversion specifier applies to a pointer to awchar_targument; or has no effect on a followinga,A,e,E,f,F,g, orGconversion specifier.
Change 7.19.6.1#8, c specifier, second paragraph, to:
If an
llength modifier is present*, the argument - whose type is that resulting when the default argument conversions are applied to the typewchar_t* - is converted as if by anlsconversion specification with no precision and an argument that points to the initial element of a two-element array ofwchar_t, the first element containing the argument to thelcconversion specification and the second a null wide character.
Change 7.24.2.1#8, c specifier, second paragraph, to:
If an
llength modifier is present, the argument is converted towchar_tand written.
Comment from WG14 on 2002-03-07:
Change the quoted line of 7.19.6.1#18 to:
fprintf(stdout, "|%13lc|\n", (wint_t) wstr[5]);