This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/80409] Document that va_arg(ap, void*) can be used to consume any pointer argument
- From: "pascal_cuoq at hotmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 12 Apr 2017 14:27:52 +0000
- Subject: [Bug c/80409] Document that va_arg(ap, void*) can be used to consume any pointer argument
- Auto-submitted: auto-generated
- References: <bug-80409-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80409
--- Comment #2 from Pascal Cuoq <pascal_cuoq at hotmail dot com> ---
> it should work even with standard c
Quoting from 7.6.1.1:2
… the behavior is undefined, except for the following cases:
* …
* one type is pointer to void and the other is a pointer to a character type.
Why would the standard say the above, if using void* with any pointer type
worked?
> for an example %p in printf takes a void* but nobody casts it to void* when passing to printf
This does not correspond to my experience. The C programmers I know fall into
two categories:
- C programmers who do not cast printf %p arguments to void*, because it works.
These programmers also write “*(float*)&uint_variable = 1.0f;”, because it
works, and “if (int_variable + 1 < int_variable) printf ("overflow!");”,
because it works.
- C programmers who do cast printf %p arguments to void*.
The good ship “we shouldn't have to document this because it obviously should
work on normal architectures even if the C standard does not say so” sailed
some time in the late nineties.