This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/80409] New: Document that va_arg(ap, void*) can be used to consume any pointer argument


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80409

            Bug ID: 80409
           Summary: Document that va_arg(ap, void*) can be used to consume
                    any pointer argument
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pascal_cuoq at hotmail dot com
  Target Milestone: ---

This bug report is vaguely related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=26542 but whereas that report asks
for removing a warning, here there is no warning and this is a request for it
to be documented that the idiom is legal in GCC.

The C11 standard allows to confuse void* and char* when consuming arguments
from a va_list, and only these types of pointers:

http://port70.net/~nsz/c/c11/n1570.html#7.16.1.1p2

As explained by Rich Felker as part of a discussion on musl's scanf
implementation, this makes it very inconvenient to implement POSIX's positional
specifiers for scanf. Clearly the intent of POSIX's “all the leading arguments,
from the first to the (N-1)th, are pointers” is to allow these arguments to be
consumed on the spot when %N$ is encountered:

http://www.openwall.com/lists/musl/2017/04/10/3

Since the open-source world divides the C compilation platform described by the
C standard into C compilers (Clang, GCC) and standard libraries (Glibc, musl,
...), with the implementation of varargs on the compiler side and the
implementation of scanf on the standard library side, it would make sense to
document that on target platforms where the representation of pointers is
uniform, the compilers allow va_arg(ap, void*) to consume any pointer argument.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]