__asm ​​__ ("__isoc99_scanf") после объявления функции - PullRequest
1 голос
/ 04 июня 2019

Я видел следующий фрагмент кода в моем предварительно обработанном C-коде. Что делает asm после объявления функции?

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

По-видимому, это делает вызов функции компилируемым в "call __isoc99_scanf" вместо "call scanf". Это стандартный синтаксис C / GCC?

1 Ответ

0 голосов
/ 04 июня 2019

Я только что нашел его реализацию в 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
...