wint_t
is not the promoted version of wchar_t
This 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_t
which 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
WEOF
below);269) and269
wchar_t
andwint_t
can 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_t
which 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
, orX
conversion specifier applies to along int
orunsigned long int
argument; that a followingn
conversion specifier applies to a pointer to along int
argument; that a followingc
conversion specifier applies to an argument whose type is that resulting when the default argument conversions are applied to the typewchar_t
; that a followings
conversion specifier applies to a pointer to awchar_t
argument; or has no effect on a followinga
,A
,e
,E
,f
,F
,g
, orG
conversion specifier.
Change 7.19.6.1#8, c
specifier, second paragraph, to:
If an
l
length 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 anls
conversion 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 thelc
conversion specification and the second a null wide character.
Change 7.24.2.1#8, c
specifier, second paragraph, to:
If an
l
length modifier is present, the argument is converted towchar_t
and 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]);