__isoc99_scanf和scanf

Aru*_*mar 9 c iso

我正在研究GCC中的各种编译器选项,并在我对要使用的标准进行更改时观察更改.

$ gcc Q1.c -Wall -save-temps -o Q1
$ vi Q1.s
Run Code Online (Sandbox Code Playgroud)

我看到其中一个操作码为

 call    __isoc99_scanf
Run Code Online (Sandbox Code Playgroud)

现在当我用C89标准编译时

$gcc Q1.c -Wall -save-temps -std=c89 -o Q1
$ vi Q1.s
Run Code Online (Sandbox Code Playgroud)

我认为操作码是

call    scanf
Run Code Online (Sandbox Code Playgroud)

这两种形式有scanf什么区别?我可以看到他们的来源的任何链接将受到高度赞赏.

oua*_*uah 9

原因是严格遵循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);
Run Code Online (Sandbox Code Playgroud)


小智 6

scanf(3)手册提到了c99中引入的几个类型修饰符:

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
Run Code Online (Sandbox Code Playgroud)