$ g++ warn.cpp -Wall -ansi no warnings. $ g++ warn.cpp -Wall -pedantic (...) format ‘%p’ expects type ‘void*’, but argument 2 has type ‘A*’ #include <cstdio> struct A {}; int main() { A* a = 0; printf("a = 0x%p\n", a); return 0; }
Indeed. Not exactly useful.
Actually the C standard says void* only. I don't see the issue here.
This is actually expected. From the C standard: p The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner.
I'd like to (probably uselessly but still) argue for reopening this bug and removing this warning. The interpretation of the standard text is open to questions: IMHO an "A *" pointer is a pointer to void, too, as any pointer in C is, implicitely, pointer to void. But most importantly I think this warning is absolutely useless and the only way to get rid of it is ugly (you need an explicit cast to "void *"). But, again, the most important argument against this warning is that it's 100% useless. Conversion of any pointer to "void *" is well defined and unambiguous (even in presence of multiple inheritance) and there is just no situation whatsoever in which this warning can indicate a real problem. Please consider suppressing it, thanks in advance!
*** Bug 28459 has been marked as a duplicate of this bug. ***
> I'd like to (probably uselessly but still) argue for reopening this bug and > removing this warning. The interpretation of the standard text is open to > questions: IMHO an "A *" pointer is a pointer to void, too, as any pointer in C > is, implicitely, pointer to void. But most importantly I think this warning is > absolutely useless and the only way to get rid of it is ugly (you need an > explicit cast to "void *"). Except IIRC a target could have void* pass different from a char* when it comes to var-args so really the warning is still correct.
Just for my personal education, could you please tell which target(s) pass "char *" differently from "void *" in this context? Thanks!
Subject: Re: bogus diagnostic with -pedantic?: format '%p'; expects type 'void*', but argument 2 has type 'A*' On Fri, 2006-12-08 at 11:07 +0000, vz-gcc at zeitlins dot org wrote: > Just for my personal education, could you please tell which target(s) > pass > "char *" differently from "void *" in this context? A made up target (at least for now). :) -- Pinski
Please consider reopening this bug. I appreciate that the relevant standards don't guarantee this idiom will always work. On the other hand, this warning is in practice only a nuisance. Balance the real work this makes for people who try to keep their code pedantic-clean against the risk that someday an architecture will come along where it matters. Could we maybe delete this warning just until we have some reason to believe that such an architecture is likely to exist someday, and then reinstate it?