__isoc99_scanf and scanf

c iso
ArunMKumar picture ArunMKumar · May 4, 2013 · Viewed 14.2k times · Source

I was studying various compiler option in GCC and observing changes when I made changes in the standard to be used.

$ gcc Q1.c -Wall -save-temps -o Q1
$ vi Q1.s

I see one of the opcodes as

 call    __isoc99_scanf

and now when I compile with the C89 standards

$gcc Q1.c -Wall -save-temps -std=c89 -o Q1
$ vi Q1.s

I see the opcode as

call    scanf

What is the difference between these two forms of scanf? Any link where I can see their source would be highly appreciated.

Answer

ouah picture ouah · May 4, 2013

The reason is strict following of c99 disallow some existing GNU extension conversion specifiers.

In glibc 2.17, in libio/stdio.h there is this comment:

/* For strict ISO C99 or POSIX compliance disallow %as, %aS and %a[
   GNU extension which conflicts with valid %a followed by letter
   s, S or [.  */
extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
    const char *__restrict __format, ...),
    __isoc99_fscanf) __wur;
extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
    __isoc99_scanf) __wur;
extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
      const char *__restrict __format, ...),
      __isoc99_sscanf);