C语言 __isoc99_scanf and scanf



我正在研究GCC中的各种编译器选项,并在我更改要使用的标准时观察变化。

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

我看到一个操作码是

 call    __isoc99_scanf

现在当我用C89标准编译时

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

我看到操作码是

call    scanf

这两种形式的scanf有什么区别?

原因是严格遵循c99禁止一些现有的GNU扩展转换说明符。

在glibc 2.17中,在libio/stdio.h中有这样的注释:

/* 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);

scanf(3)手册提到1999年引入的几个类型修饰符:

j      As for h, but the next pointer is a pointer to an intmax_t or a uintmax_t.  This modifier was introduced in C99
t      As for h, but the next pointer is a pointer to a ptrdiff_t.  This modifier was introduced in C99.
z      As for h, but the next pointer is a pointer to a size_t.  This modifier was introduced in C99.
a      (C99) Equivalent to f

最新更新