This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix 2 clang warnings.
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: Martin Sebor <msebor at gmail dot com>, Martin Liška <mliska at suse dot cz>, Jakub Jelinek <jakub at redhat dot com>, <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 9 Aug 2019 21:38:02 +0000
- Subject: Re: [PATCH] Fix 2 clang warnings.
- Ironport-sdr: jeUfuPAZbg7WzPUWyE/hR279eTfevzSBZGbk4s0CsxS4Wj508T/2hqOrjKFPy1UIRiCTZzdjke mD2fylkBnU+zX9q33SStW6qkIO0GHC2DXpJJrQSGTOt8qqeVlknZoOgbvXkjZ0BFhH/7i/e75a GZNKj8hKpk9h29kpCgFB/ivN1Bebf/SZKJ0LTjDNht31cVj75OrZ0y+tkndXiWFpBd40WOSHfP wcqshKhop6TeCO8hwaplRW+00W10Wsd4VssBnxb4TqOcCvwKSb8V0XY0a8z+d9IhUtBIPtdiFb XMI=
- Ironport-sdr: x4rG0bXMFUg6Qgkli95BDYhsGu/VxtGilLXKnyQJlPtZCbw93Pv/wRK6GGGqCQ5BayUgaI/XqI XJ+kp91f5nmXeMPMIhFluWoe1Xsci/vTmduV4qCHssyIJXs1+QteUG4Ne8zkDcTOQt0fYI/4oZ C9Ge7qx/tYSMrEhzXxubD8rqwdzCxF1j+MC227r6EJ04VMXNU9PcEmUbzhxN38pud46YS+1kx5 tUBX5MVQsZbd3YQGZBm/DWeBi34bRtoBdUIKFGOoujwX0a17YnVR5mvVjcLrCxthMW0tcTem/r N2I=
- References: <3fb1b321-62e3-4165-c391-29006b9f3cc9@suse.cz> <20190627141129.GZ815@tucnak> <e3782971-bb0a-de37-eed9-a339131274c0@suse.cz> <302247eb-1180-468c-3e11-491567cd2ec5@gmail.com> <20190629160936.GA18316@gate.crashing.org>
On Sat, 29 Jun 2019, Segher Boessenkool wrote:
> So I'd say that yes, void * and char * are interchangeable as arguments
> to variable argument functions as well.
They are explicitly interchangeable as arguments to variable argument
functions using va_arg; the definition of va_arg specifies that "one type
is a signed integer type, the other type is the corresponding unsigned
integer type, and the value is representable in both types" and "one type
is pointer to void and the other is a pointer to a character type" are
both allowed.
So this is one of those questions about whether printf is required to
behave as if implemented in C using va_arg, or whether the specification
of argument types to printf being stricter than what's allowed for va_arg
imposes extra requirements on callers of printf.
This is where gcc.dg/format/c90-printf-1.c has the comment
/* With -pedantic, we want some further checks for pointer targets:
%p should allow only pointers to void (possibly qualified) and
to character types (possibly qualified), but not function pointers
or pointers to other types. (Whether, in fact, character types are
allowed here is unclear; see thread on comp.std.c, July 2000 for
discussion of the requirements of rules on identical representation,
and of the application of the as if rule with the new va_arg
allowances in C99 to printf.) Likewise, we should warn if
pointer targets differ in signedness, except in some circumstances
for character pointers. (In C99 we should consider warning for
char * or unsigned char * being passed to %hhn, even if strictly
legitimate by the standard.)
*/
[...]
/* Allow character pointers with %p. */
printf ("%p%p%p%p", s, ss, us, css);
--
Joseph S. Myers
joseph@codesourcery.com