函数声明后__asm __(“ __ isoc99_scanf”)

时间:2019-06-04 13:07:47

标签: c gcc assembly inline-assembly function-declaration

我在预处理的C代码中看到了以下代码。函数声明后 asm 会做什么?

extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf");

显然,它使函数调用编译为“调用__isoc99_scanf”,而不是“调用scanf”。这是C / GCC标准语法吗?

1 个答案:

答案 0 :(得分:0)

我刚刚在glibc下的stdio-common/isoc99_scanf.c中找到了其实现,如下所示。

/* Copyright (C) 1991-2019 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.
   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.
   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */
#include <stdarg.h>
#include <stdio.h>
#include <libioP.h>
/* Read formatted input from stdin according to the format string FORMAT.  */
int
__isoc99_scanf (const char *format, ...)
{
  va_list arg;
  int done;
  va_start (arg, format);
  done = __vfscanf_internal (stdin, format, arg, SCANF_ISOC99_A);
  va_end (arg);
  return done;
}

libio/stdio.h下,它的清白性也存在。

 #if defined __USE_ISOC99 && !defined __USE_GNU \
     && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
     && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
 # ifdef __REDIRECT
 /* 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 (sscanf, (__const char *__restrict __s,
                                 __const char *__restrict __format, ...),
                        __isoc99_sscanf) __THROW;
 # else
 extern int __isoc99_fscanf (FILE *__restrict __stream,
                             __const char *__restrict __format, ...) __wur;
 extern int __isoc99_scanf (__const char *__restrict __format, ...) __wur;
 extern int __isoc99_sscanf (__const char *__restrict __s,
                             __const char *__restrict __format, ...) __THROW;
 #  define fscanf __isoc99_fscanf
 #  define scanf __isoc99_scanf
 #  define sscanf __isoc99_sscanf
 # endif
 #endif