[PATCH] manual: Document the standardized scanf flag, "m". [BZ #16376]

Zack Weinberg zackw@panix.com
Fri Feb 9 23:46:00 GMT 2018


On Fri, Feb 9, 2018 at 11:39 AM, Joseph Myers <joseph@codesourcery.com> wrote:
> On Fri, 9 Feb 2018, Zack Weinberg wrote:
>
>> > +As a GNU extension predating @samp{m}, @samp{a} is also available, but
>> > +its use is considered deprecated.
>>
>> let's be a little more specific here:
>>
>> +As a GNU extension, the modifier @samp{a} has the same effect as @samp{m}.
>> +This extension predates POSIX.1-2008 and is now deprecated.  Other C libraries
>> +may interpret e.g.@: @samp{%as} as the @samp{%a} format for reading
>> +floating-point numbers, followed by a literal @samp{s}.
>
> Which glibc does in the absence of _GNU_SOURCE, since __USE_XOPEN2K is
> defined by default.  The redirection to __isoc99_scanf etc. is done if:
>
> #if defined __USE_ISOC99 && !defined __USE_GNU \
>     && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
>     && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)

I'm tempted to suggest that we drop the __USE_GNU - meaning that 'a'
would only be a modifier under -std=gnu89, if I'm reading that
correctly - both because it'll be easier to document, and because this
seems to be already what GCC's scanf format warnings do:

$ cat test.c
#include <stdio.h>

int main(void)
{
  char *s;
  scanf("%as", &s);
  puts(s);
  return 0;
}

$ gcc -std=gnu89 -Wformat test.c
$ gcc -std=gnu11 -Wformat test.c
test.c: In function ‘main’:
test.c:6:11: warning: format ‘%a’ expects argument of type ‘float *’,
but argument 2 has type ‘char **’ [-Wformat=]
   scanf("%as", &s);
          ~^    ~~
$ gcc -std=gnu11 -Wformat -D_GNU_SOURCE test.c
test.c: In function ‘main’:
test.c:6:11: warning: format ‘%a’ expects argument of type ‘float *’,
but argument 2 has type ‘char **’ [-Wformat=]
   scanf("%as", &s);
          ~^    ~~

$ gcc --version
gcc (Debian 7.3.0-3) 7.3.0



More information about the Libc-alpha mailing list