本文基于《深入理解计算机系统》第一章内容,通过一个简单的 C 程序,深入剖析计算机系统的工作原理。
核心概念:什么是计算机系统?
计算机系统 = 硬件 + 软件
系统中所有信息(代码、数据等)均以比特表示。
由 ASCII 字符构成的人类可读文件称为文本文件,除文本文件外的所有其他文件都称为二进制文件。
从源代码到可执行文件:一个完整的转换过程
以下通过一个简单的C程序 hello.c
,展示其通过编译系统转化为可执行文件的过程,揭示从高级语言到机器代码的转换。
示例程序:hello.c
(文本)
以下是一个简单的C程序,打印“hello world”并返回0:
#include <stdio.h>
int main() {
printf("hello world\n");
return 0;
}
编译系统流程
编译系统将hello.c
转化为可执行文件hello.exe
,经历以下四个阶段:
- 预处理:将头文件和宏展开,生成
hello.i
。 - 编译:将C代码翻译为汇编代码,生成
hello.s
。 - 汇编:将汇编代码转化为机器码,生成
hello.o
。 - 链接:将
hello.o
与库文件(如printf.o
)合并,生成可执行文件hello.exe
。
第一阶段:预处理 Preprocessing
转换:hello.c
→ hello.i
(文本文件)
核心工作:
- 处理
#include
指令,将头文件内容插入源文件 - 展开宏定义(
#define
) - 处理条件编译指令(
#ifdef
,#ifndef
) - 删除注释
输出示例:
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#ifndef _INC_STDIO
#define _INC_STDIO
#include <corecrt_stdio_config.h>
#pragma pack(push,_CRT_PACKING)
#pragma push_macro("snprintf")
#undef snprintf
#pragma push_macro("vsnprintf")
#undef vsnprintf
#pragma push_macro("snwprintf")
#undef snwprintf
#pragma push_macro("vsnwprintf")
#undef vsnwprintf
#ifdef __cplusplus
extern "C" {
#endif
#define BUFSIZ 512
#define _NFILE _NSTREAM_
#define _NSTREAM_ 512
#define _IOB_ENTRIES 20
#define EOF (-1)
#ifndef _FILE_DEFINED
struct _iobuf {
#ifdef _UCRT
void *_Placeholder;
#else
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char *_tmpfname;
#endif
};
typedef struct _iobuf FILE;
#define _FILE_DEFINED
#endif
#ifdef _POSIX_
#define _P_tmpdir "/"
#define _wP_tmpdir L"/"
#else
#define _P_tmpdir "\\"
#define _wP_tmpdir L"\\"
#endif
#ifdef _UCRT
#define L_tmpnam 260
#else
#define L_tmpnam (sizeof(_P_tmpdir) + 12)
#endif
#ifdef _POSIX_
#define L_ctermid 9
#define L_cuserid 32
#endif
#define SEEK_CUR 1
#define SEEK_END 2
#define SEEK_SET 0
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#define FILENAME_MAX 260
#define FOPEN_MAX 20
#define _SYS_OPEN 20
#ifdef _UCRT
#define TMP_MAX 2147483647
#else
#define TMP_MAX 32767
#endif
#ifndef NULL
#ifdef __cplusplus
#ifndef _WIN64
#define NULL 0
#else
#define NULL 0LL
#endif /* W64 */
#else
#define NULL ((void *)0)
#endif
#endif
#include <_mingw_off_t.h>
_CRTIMP FILE *__cdecl __acrt_iob_func(unsigned index);
#ifndef _STDIO_DEFINED
_CRTIMP FILE *__cdecl __iob_func(void);
#define _iob __iob_func()
#endif
#ifndef _FPOS_T_DEFINED
#define _FPOS_T_DEFINED
#undef _FPOSOFF
#if (!defined(NO_OLDNAMES) || defined(__GNUC__))
__MINGW_EXTENSION typedef __int64 fpos_t;
#define _FPOSOFF(fp) ((long)(fp))
#else
__MINGW_EXTENSION typedef long long fpos_t;
#define _FPOSOFF(fp) ((long)(fp))
#endif
#endif
#ifndef _STDSTREAM_DEFINED
#define _STDSTREAM_DEFINED
#define stdin (__acrt_iob_func(0))
#define stdout (__acrt_iob_func(1))
#define stderr (__acrt_iob_func(2))
#endif
#define _IOFBF 0x0000
#define _IOLBF 0x0040
#define _IONBF 0x0004
#ifndef _UCRT
#define _IOREAD 0x0001
#define _IOWRT 0x0002
#define _IOMYBUF 0x0008
#define _IOEOF 0x0010
#define _IOERR 0x0020
#define _IOSTRG 0x0040
#define _IORW 0x0080
#ifdef _POSIX_
#define _IOAPPEND 0x0200
#endif
#endif
/* used with _set_output_format which is not present in ucrt */
#ifndef _UCRT
#define _TWO_DIGIT_EXPONENT 0x1
#endif
#if __MINGW_FORTIFY_LEVEL > 0
__mingw_bos_declare;
#endif
#ifndef _STDIO_DEFINED
extern
__MINGW_GNU_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...);
extern
__MINGW_GNU_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_vsscanf (const char * __restrict__ _Str,const char * __restrict__ Format,va_list argp);
extern
__MINGW_GNU_SCANF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_scanf(const char * __restrict__ _Format,...);
extern
__MINGW_GNU_SCANF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_vscanf(const char * __restrict__ Format, va_list argp);
extern
__MINGW_GNU_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_fscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,...);
extern
__MINGW_GNU_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_vfscanf (FILE * __restrict__ fp, const char * __restrict__ Format,va_list argp);
extern
__MINGW_GNU_PRINTF(3, 0) __MINGW_ATTRIB_NONNULL(3)
int __cdecl __mingw_vsnprintf(char * __restrict__ _DstBuf,size_t _MaxCount,const char * __restrict__ _Format,
va_list _ArgList);
extern
__MINGW_GNU_PRINTF(3, 4) __MINGW_ATTRIB_NONNULL(3)
int __cdecl __mingw_snprintf(char * __restrict__ s, size_t n, const char * __restrict__ format, ...);
extern
__MINGW_GNU_PRINTF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_printf(const char * __restrict__ , ... ) __MINGW_NOTHROW;
extern
__MINGW_GNU_PRINTF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_vprintf (const char * __restrict__ , va_list) __MINGW_NOTHROW;
extern
__MINGW_GNU_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_fprintf (FILE * __restrict__ , const char * __restrict__ , ...) __MINGW_NOTHROW;
extern
__MINGW_GNU_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_vfprintf (FILE * __restrict__ , const char * __restrict__ , va_list) __MINGW_NOTHROW;
extern
__MINGW_GNU_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_sprintf (char * __restrict__ , const char * __restrict__ , ...) __MINGW_NOTHROW;
extern
__MINGW_GNU_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_vsprintf (char * __restrict__ , const char * __restrict__ , va_list) __MINGW_NOTHROW;
extern
__MINGW_GNU_PRINTF(2, 3) __attribute__((nonnull (1,2)))
int __cdecl __mingw_asprintf(char ** __restrict__ , const char * __restrict__ , ...) __MINGW_NOTHROW;
extern
__MINGW_GNU_PRINTF(2, 0) __attribute__((nonnull (1,2)))
int __cdecl __mingw_vasprintf(char ** __restrict__ , const char * __restrict__ , va_list) __MINGW_NOTHROW;
extern
__MINGW_MS_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...)
__MINGW_UCRT_ASM_CALL(sscanf);
extern
__MINGW_MS_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_vsscanf(const char * __restrict__ _Str,const char * __restrict__ _Format,va_list argp)
__MINGW_ASM_CALL(vsscanf);
extern
__MINGW_MS_SCANF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_scanf(const char * __restrict__ _Format,...)
__MINGW_UCRT_ASM_CALL(scanf);
extern
__MINGW_MS_SCANF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_vscanf(const char * __restrict__ _Format,va_list argp)
__MINGW_ASM_CALL(vscanf);
extern
__MINGW_MS_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_fscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,...)
__MINGW_UCRT_ASM_CALL(fscanf);
extern
__MINGW_MS_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_vfscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,va_list argp)
__MINGW_ASM_CALL(vfscanf);
extern
__MINGW_MS_PRINTF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_printf(const char * __restrict__ , ... )
__MINGW_UCRT_ASM_CALL(printf) __MINGW_NOTHROW;
extern
__MINGW_MS_PRINTF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_vprintf (const char * __restrict__ , va_list)
__MINGW_UCRT_ASM_CALL(vprintf) __MINGW_NOTHROW;
extern
__MINGW_MS_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_fprintf (FILE * __restrict__ , const char * __restrict__ , ...)
__MINGW_UCRT_ASM_CALL(fprintf) __MINGW_NOTHROW;
extern
__MINGW_MS_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_vfprintf (FILE * __restrict__ , const char * __restrict__ , va_list)
__MINGW_UCRT_ASM_CALL(vfprintf) __MINGW_NOTHROW
;
extern
__MINGW_MS_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_sprintf (char * __restrict__ , const char * __restrict__ , ...)
__MINGW_UCRT_ASM_CALL(sprintf) __MINGW_NOTHROW;
extern
__MINGW_MS_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_vsprintf (char * __restrict__ , const char * __restrict__ , va_list)
__MINGW_UCRT_ASM_CALL(vsprintf) __MINGW_NOTHROW;
extern
__MINGW_MS_PRINTF(3, 4) __MINGW_ATTRIB_NONNULL(3)
int __cdecl __ms_snprintf (char * __restrict__ , size_t , const char * __restrict__ , ...)
__MINGW_UCRT_ASM_CALL(snprintf) __MINGW_NOTHROW;
extern
__MINGW_MS_PRINTF(3, 0) __MINGW_ATTRIB_NONNULL(3)
int __cdecl __ms_vsnprintf (char * __restrict__ , size_t , const char * __restrict__ , va_list)
__MINGW_UCRT_ASM_CALL(vsnprintf) __MINGW_NOTHROW;
#ifdef _UCRT
int __cdecl __stdio_common_vsprintf(unsigned __int64 options, char *str, size_t len, const char *format, _locale_t locale, va_list valist);
int __cdecl __stdio_common_vfprintf(unsigned __int64 options, FILE *file, const char *format, _locale_t locale, va_list valist);
int __cdecl __stdio_common_vsscanf(unsigned __int64 options, const char *input, size_t length, const char *format, _locale_t locale, va_list valist);
int __cdecl __stdio_common_vfscanf(unsigned __int64 options, FILE *file, const char *format, _locale_t locale, va_list valist);
#endif
#undef __MINGW_PRINTF_FORMAT
#undef __MINGW_SCANF_FORMAT
#if defined(__clang__)
#define __MINGW_PRINTF_FORMAT __printf__
#define __MINGW_SCANF_FORMAT __scanf__
#elif defined(_UCRT) || __USE_MINGW_ANSI_STDIO
#define __MINGW_PRINTF_FORMAT __gnu_printf__
#define __MINGW_SCANF_FORMAT __gnu_scanf__
#else
#define __MINGW_PRINTF_FORMAT __ms_printf__
#define __MINGW_SCANF_FORMAT __ms_scanf__
#endif
#if __USE_MINGW_ANSI_STDIO && !defined(_CRTBLD)
/*
* User has expressed a preference for C99 conformance...
*/
#ifdef _GNU_SOURCE
__MINGW_GNU_PRINTF(2, 3) __attribute__((nonnull (1,2)))
int asprintf(char **__ret, const char *__format, ...)
__MINGW_ASM_CALL(__mingw_asprintf);
__MINGW_GNU_PRINTF(2, 0) __attribute__((nonnull (1,2)))
int vasprintf(char **__ret, const char *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vasprintf);
#endif /* _GNU_SOURCE */
/* There seems to be a bug about builtins and static overrides of them
in g++. So we need to do here some trickery. */
#ifdef __cplusplus
extern "C++" {
#endif
__MINGW_GNU_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int sscanf(const char *__source, const char *__format, ...)
__MINGW_ASM_CALL(__mingw_sscanf);
__MINGW_GNU_SCANF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int scanf(const char *__format, ...)
__MINGW_ASM_CALL(__mingw_scanf);
__MINGW_GNU_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int fscanf(FILE *__stream, const char *__format, ...)
__MINGW_ASM_CALL(__mingw_fscanf);
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
__MINGW_GNU_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int vsscanf (const char *__source, const char *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vsscanf);
__MINGW_GNU_SCANF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int vscanf(const char *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vscanf);
__MINGW_GNU_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int vfscanf (FILE *__stream, const char *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vfscanf);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif /* __NO_ISOCEXT */
__MINGW_GNU_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int fprintf (FILE *__stream, const char *__format, ...)
__MINGW_ASM_CALL(__mingw_fprintf);
__MINGW_GNU_PRINTF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int printf (const char *__format, ...)
__MINGW_ASM_CALL(__mingw_printf);
__MINGW_GNU_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int sprintf (char *__stream, const char *__format, ...)
__MINGW_ASM_CALL(__mingw_sprintf);
#if __MINGW_FORTIFY_VA_ARG
__mingw_bos_extern_ovr
__MINGW_GNU_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int sprintf (char *__stream, const char *__format, ...)
{
if (__mingw_bos_known(__stream)) {
int __retval = __mingw_snprintf( __stream, __mingw_bos(__stream, 1), __format, __builtin_va_arg_pack() );
if (__retval >= 0)
__mingw_bos_ptr_chk(__stream, (size_t)__retval + 1, 1);
return __retval;
}
return __mingw_sprintf( __stream, __format, __builtin_va_arg_pack() );
}
#endif /* __MINGW_FORTIFY_VA_ARG */
__MINGW_GNU_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int vfprintf (FILE *__stream, const char *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vfprintf);
__MINGW_GNU_PRINTF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int vprintf (const char *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vprintf);
__mingw_bos_ovr
__MINGW_GNU_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int vsprintf (char *__stream, const char *__format, __builtin_va_list __local_argv)
{
#if __MINGW_FORTIFY_LEVEL > 0
if (__mingw_bos_known(__stream)) {
int __retval = __mingw_vsnprintf( __stream, __mingw_bos(__stream, 1), __format, __local_argv );
if (__retval >= 0)
__mingw_bos_ptr_chk(__stream, (size_t)__retval + 1, 1);
return __retval;
}
#endif
return __mingw_vsprintf( __stream, __format, __local_argv );
}
/* #ifndef __NO_ISOCEXT */ /* externs in libmingwex.a */
__MINGW_GNU_PRINTF(3, 4) __MINGW_ATTRIB_NONNULL(3)
int snprintf (char *__stream, size_t __n, const char *__format, ...)
__MINGW_ASM_CALL(__mingw_snprintf);
#if __MINGW_FORTIFY_VA_ARG
__mingw_bos_extern_ovr
__MINGW_GNU_PRINTF(3, 4) __MINGW_ATTRIB_NONNULL(3)
int snprintf (char *__stream, size_t __n, const char *__format, ...)
{
__mingw_bos_ptr_chk_warn(__stream, __n, 1);
return __mingw_snprintf( __stream, __n, __format, __builtin_va_arg_pack() );
}
#endif /* __MINGW_FORTIFY_VA_ARG */
__mingw_bos_ovr
__MINGW_GNU_PRINTF(3, 0) __MINGW_ATTRIB_NONNULL(3)
int vsnprintf (char *__stream, size_t __n, const char *__format, __builtin_va_list __local_argv)
{
#if __MINGW_FORTIFY_LEVEL > 0
__mingw_bos_ptr_chk_warn(__stream, __n, 1);
#endif
return __mingw_vsnprintf( __stream, __n, __format, __local_argv );
}
/* Override __builtin_printf-routines ... Kludge for libstdc++ ...*/
#define __builtin_vsnprintf __mingw_vsnprintf
#define __builtin_vsprintf __mingw_vsprintf
/* #endif */ /* __NO_ISOCEXT */
#ifdef __cplusplus
}
#endif
#else /* !__USE_MINGW_ANSI_STDIO */
#undef __builtin_vsnprintf
#undef __builtin_vsprintf
/*
* Default configuration: simply direct all calls to MSVCRT...
*/
#ifdef _UCRT
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 2, 3))) __MINGW_ATTRIB_NONNULL(2)
int __cdecl fprintf(FILE * __restrict__ _File,const char * __restrict__ _Format,...);
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 1, 2))) __MINGW_ATTRIB_NONNULL(1)
int __cdecl printf(const char * __restrict__ _Format,...);
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 2, 3))) __MINGW_ATTRIB_NONNULL(2)
int __cdecl sprintf(char * __restrict__ _Dest,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 2, 0))) __MINGW_ATTRIB_NONNULL(2)
int __cdecl vfprintf(FILE * __restrict__ _File,const char * __restrict__ _Format,va_list _ArgList);
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 1, 0))) __MINGW_ATTRIB_NONNULL(1)
int __cdecl vprintf(const char * __restrict__ _Format,va_list _ArgList);
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 2, 0))) __MINGW_ATTRIB_NONNULL(2)
int __cdecl vsprintf(char * __restrict__ _Dest,const char * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__MINGW_ATTRIB_DEPRECATED_SEC_WARN
__attribute__((__format__ (__MINGW_SCANF_FORMAT, 2, 3))) __MINGW_ATTRIB_NONNULL(2)
int __cdecl fscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,...);
__MINGW_ATTRIB_DEPRECATED_SEC_WARN
__attribute__((__format__ (__MINGW_SCANF_FORMAT, 1, 2))) __MINGW_ATTRIB_NONNULL(1)
int __cdecl scanf(const char * __restrict__ _Format,...);
__MINGW_ATTRIB_DEPRECATED_SEC_WARN
__attribute__((__format__ (__MINGW_SCANF_FORMAT, 2, 3))) __MINGW_ATTRIB_NONNULL(2)
int __cdecl sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...);
#ifdef _GNU_SOURCE
__attribute__ ((__format__ (__MINGW_PRINTF_FORMAT, 2, 0)))
int __cdecl vasprintf(char ** __restrict__ _Ret,const char * __restrict__ _Format,va_list _Args);
__attribute__ ((__format__ (__MINGW_PRINTF_FORMAT, 2, 3)))
int __cdecl asprintf(char ** __restrict__ _Ret,const char * __restrict__ _Format,...);
#endif /*_GNU_SOURCE*/
__attribute__((__format__ (__MINGW_SCANF_FORMAT, 2, 0))) __MINGW_ATTRIB_NONNULL(2)
int vfscanf (FILE *__stream, const char *__format, __builtin_va_list __local_argv);
__attribute__((__format__ (__MINGW_SCANF_FORMAT, 2, 0))) __MINGW_ATTRIB_NONNULL(2)
int vsscanf (const char * __restrict__ __source, const char * __restrict__ __format, __builtin_va_list __local_argv);
__attribute__((__format__ (__MINGW_SCANF_FORMAT, 1, 0))) __MINGW_ATTRIB_NONNULL(1)
int vscanf(const char *__format, __builtin_va_list __local_argv);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#else
__MINGW_MS_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl fprintf(FILE * __restrict__ _File,const char * __restrict__ _Format,...);
__MINGW_MS_PRINTF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int __cdecl printf(const char * __restrict__ _Format,...);
__MINGW_MS_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl sprintf(char * __restrict__ _Dest,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__MINGW_MS_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl vfprintf(FILE * __restrict__ _File,const char * __restrict__ _Format,va_list _ArgList);
__MINGW_MS_PRINTF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int __cdecl vprintf(const char * __restrict__ _Format,va_list _ArgList);
__MINGW_MS_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int __cdecl vsprintf(char * __restrict__ _Dest,const char * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__MINGW_MS_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl fscanf(FILE * __restrict__ _File,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__MINGW_MS_SCANF(1, 2) __MINGW_ATTRIB_NONNULL(1)
int __cdecl scanf(const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__MINGW_MS_SCANF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int __cdecl sscanf(const char * __restrict__ _Src,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
#ifdef _GNU_SOURCE
int __cdecl vasprintf(char ** __restrict__ __ret,const char * __restrict__ __format,va_list __ap) __attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 0)));
int __cdecl asprintf(char ** __restrict__ __ret,const char * __restrict__ __format,...) __attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3)));
#endif /*_GNU_SOURCE*/
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
__MINGW_MS_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int vfscanf (FILE *__stream, const char *__format, __builtin_va_list __local_argv);
__MINGW_MS_SCANF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int vsscanf (const char * __restrict__ __source, const char * __restrict__ __format, __builtin_va_list __local_argv);
__MINGW_MS_SCANF(1, 0) __MINGW_ATTRIB_NONNULL(1)
int vscanf(const char *__format, __builtin_va_list __local_argv);
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif /* __NO_ISOCEXT */
#endif /* _UCRT */
#endif /* __USE_MINGW_ANSI_STDIO */
_CRTIMP int __cdecl _filbuf(FILE *_File);
_CRTIMP int __cdecl _flsbuf(int _Ch,FILE *_File);
#ifdef _POSIX_
_CRTIMP FILE *__cdecl _fsopen(const char *_Filename,const char *_Mode);
#else
_CRTIMP FILE *__cdecl _fsopen(const char *_Filename,const char *_Mode,int _ShFlag);
#endif
void __cdecl clearerr(FILE *_File);
int __cdecl fclose(FILE *_File);
_CRTIMP int __cdecl _fcloseall(void);
#ifdef _POSIX_
FILE *__cdecl fdopen(int _FileHandle,const char *_Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#else
_CRTIMP FILE *__cdecl _fdopen(int _FileHandle,const char *_Mode);
#endif
int __cdecl feof(FILE *_File);
int __cdecl ferror(FILE *_File);
int __cdecl fflush(FILE *_File);
int __cdecl fgetc(FILE *_File);
_CRTIMP int __cdecl _fgetchar(void);
int __cdecl fgetpos(FILE * __restrict__ _File ,fpos_t * __restrict__ _Pos); /* 64bit only, no 32bit version */
int __cdecl fgetpos64(FILE * __restrict__ _File ,fpos_t * __restrict__ _Pos); /* fgetpos already 64bit */
char *__cdecl fgets(char * __restrict__ _Buf,int _MaxCount,FILE * __restrict__ _File);
_CRTIMP int __cdecl _fileno(FILE *_File);
#ifdef _POSIX_
int __cdecl fileno(FILE *_File) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#endif
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("_tempnam")
#undef _tempnam
#endif
_CRTIMP char *__cdecl _tempnam(const char *_DirName,const char *_FilePrefix);
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_tempnam")
#endif
_CRTIMP int __cdecl _flushall(void);
FILE *__cdecl fopen(const char * __restrict__ _Filename,const char * __restrict__ _Mode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
FILE *__cdecl fopen64(const char * __restrict__ filename,const char * __restrict__ mode);
int __cdecl fputc(int _Ch,FILE *_File);
_CRTIMP int __cdecl _fputchar(int _Ch);
int __cdecl fputs(const char * __restrict__ _Str,FILE * __restrict__ _File);
size_t __cdecl fread(void * __restrict__ _DstBuf,size_t _ElementSize,size_t _Count,FILE * __restrict__ _File);
FILE *__cdecl freopen(const char * __restrict__ _Filename,const char * __restrict__ _Mode,FILE * __restrict__ _File) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
FILE *__cdecl freopen64(const char * __restrict__ _Filename,const char * __restrict__ _Mode,FILE * __restrict__ _File);
int __cdecl fsetpos(FILE *_File,const fpos_t *_Pos);
int __cdecl fsetpos64(FILE *_File,const fpos_t *_Pos); /* fsetpos already 64bit */
int __cdecl fseek(FILE *_File,long _Offset,int _Origin);
long __cdecl ftell(FILE *_File);
_CRTIMP int __cdecl _fseeki64(FILE *_File,__int64 _Offset,int _Origin);
_CRTIMP __int64 __cdecl _ftelli64(FILE *_File);
_CRTIMP int __cdecl fseeko(FILE *_File, _off_t _Offset, int _Origin);
_CRTIMP int __cdecl fseeko64(FILE *_File, _off64_t _Offset, int _Origin);
_CRTIMP _off_t __cdecl ftello(FILE *_File);
_CRTIMP _off64_t __cdecl ftello64(FILE *_File);
#ifndef _FILE_OFFSET_BITS_SET_FSEEKO
#define _FILE_OFFSET_BITS_SET_FSEEKO
#if (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
#define fseeko fseeko64
#endif /* (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)) */
#endif /* _FILE_OFFSET_BITS_SET_FSEEKO */
#ifndef _FILE_OFFSET_BITS_SET_FTELLO
#define _FILE_OFFSET_BITS_SET_FTELLO
#if (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64))
#define ftello ftello64
#endif /* (defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)) */
#endif /* _FILE_OFFSET_BITS_SET_FTELLO */
size_t __cdecl fwrite(const void * __restrict__ _Str,size_t _Size,size_t _Count,FILE * __restrict__ _File);
int __cdecl getc(FILE *_File);
int __cdecl getchar(void);
_CRTIMP int __cdecl _getmaxstdio(void);
char *__cdecl gets(char *_Buffer)
__attribute__((__warning__("Using gets() is always unsafe - use fgets() instead")));
int __cdecl _getw(FILE *_File);
#ifndef _CRT_PERROR_DEFINED
#define _CRT_PERROR_DEFINED
void __cdecl perror(const char *_ErrMsg);
#endif
#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
_CRTIMP int __cdecl _pclose(FILE *_File);
_CRTIMP FILE *__cdecl _popen(const char *_Command,const char *_Mode);
#if !defined(NO_OLDNAMES) && !defined(popen)
#define popen _popen
#define pclose _pclose
#endif
#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */
int __cdecl putc(int _Ch,FILE *_File);
int __cdecl putchar(int _Ch);
int __cdecl puts(const char *_Str);
_CRTIMP int __cdecl _putw(int _Word,FILE *_File);
#ifndef _CRT_DIRECTORY_DEFINED
#define _CRT_DIRECTORY_DEFINED
int __cdecl remove(const char *_Filename);
int __cdecl rename(const char *_OldFilename,const char *_NewFilename);
_CRTIMP int __cdecl _unlink(const char *_Filename);
#ifndef NO_OLDNAMES
int __cdecl unlink(const char *_Filename) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#endif
#endif
void __cdecl rewind(FILE *_File);
_CRTIMP int __cdecl _rmtmp(void);
void __cdecl setbuf(FILE * __restrict__ _File,char * __restrict__ _Buffer) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl _setmaxstdio(int _Max);
_CRTIMP unsigned int __cdecl _set_output_format(unsigned int _Format);
_CRTIMP unsigned int __cdecl _get_output_format(void);
int __cdecl setvbuf(FILE * __restrict__ _File,char * __restrict__ _Buf,int _Mode,size_t _Size);
#ifdef _UCRT
__MINGW_ATTRIB_PURE
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 1, 2))) __MINGW_ATTRIB_NONNULL(1)
int __cdecl _scprintf(const char * __restrict__ _Format,...);
__attribute__((__format__ (__MINGW_SCANF_FORMAT, 3, 4))) __MINGW_ATTRIB_NONNULL(3)
int __cdecl _snscanf(const char * __restrict__ _Src,size_t _MaxCount,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
#else
__MINGW_ATTRIB_PURE
__MINGW_MS_PRINTF(1, 2) __MINGW_ATTRIB_NONNULL(1)
_CRTIMP int __cdecl _scprintf(const char * __restrict__ _Format,...);
__MINGW_MS_SCANF(3, 4) __MINGW_ATTRIB_NONNULL(3)
_CRTIMP int __cdecl _snscanf(const char * __restrict__ _Src,size_t _MaxCount,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
#endif
__MINGW_ATTRIB_PURE
__MINGW_MS_PRINTF(1, 0) __MINGW_ATTRIB_NONNULL(1)
_CRTIMP int __cdecl _vscprintf(const char * __restrict__ _Format,va_list _ArgList);
FILE *__cdecl tmpfile(void) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
FILE *__cdecl tmpfile64(void);
char *__cdecl tmpnam(char *_Buffer);
int __cdecl ungetc(int _Ch,FILE *_File);
#ifdef _UCRT
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 3, 0))) __MINGW_ATTRIB_NONNULL(3)
int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const char * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 3, 4))) __MINGW_ATTRIB_NONNULL(3)
int __cdecl _snprintf(char * __restrict__ _Dest,size_t _Count,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
#else
__MINGW_MS_PRINTF(3, 4) __MINGW_ATTRIB_NONNULL(3)
_CRTIMP int __cdecl _snprintf(char * __restrict__ _Dest,size_t _Count,const char * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
__MINGW_MS_PRINTF(3, 0) __MINGW_ATTRIB_NONNULL(3)
_CRTIMP int __cdecl _vsnprintf(char * __restrict__ _Dest,size_t _Count,const char * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
#endif
#if __MINGW_FORTIFY_LEVEL > 0
char * __cdecl __gets_chk(char *, size_t);
char * __cdecl __mingw_call_gets_warn(char *) __MINGW_ASM_CALL(gets)
__attribute__((__warning__("Using gets() is always unsafe - use fgets() instead")));
char * __cdecl __mingw_call_fgets(char * __restrict__, int, FILE * __restrict__) __MINGW_ASM_CALL(fgets);
size_t __cdecl __mingw_call_fread(void * __restrict__, size_t, size_t, FILE * __restrict__) __MINGW_ASM_CALL(fread);
char * __cdecl __mingw_call_tmpnam(char *) __MINGW_ASM_CALL(tmpnam);
__mingw_bos_extern_ovr
char * gets(char * __dst)
{
if (__mingw_bos_known(__dst))
return __gets_chk(__dst, __mingw_bos(__dst, 1));
return __mingw_call_gets_warn(__dst);
}
__mingw_bos_extern_ovr
char * fgets(char * __restrict__ __dst, int __n, FILE * __restrict__ __f)
{
__mingw_bos_ptr_chk_warn(__dst, __n, 1);
return __mingw_call_fgets(__dst, __n, __f);
}
__mingw_bos_extern_ovr
size_t fread(void * __restrict__ __dst, size_t __sz, size_t __n, FILE * __restrict__ __f)
{
__mingw_bos_ptr_chk_warn(__dst, __sz * __n, 0);
return __mingw_call_fread(__dst, __sz, __n, __f);
}
__mingw_bos_extern_ovr
char * tmpnam(char * __dst)
{
__mingw_bos_ptr_chk_warn(__dst, L_tmpnam, 1);
return __mingw_call_tmpnam(__dst);
}
#endif /* __MINGW_FORTIFY_LEVEL > 0 */
#if __USE_MINGW_ANSI_STDIO == 0
#ifdef _UCRT
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 3, 0))) __MINGW_ATTRIB_NONNULL(3)
int vsnprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, va_list __local_argv);
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 3, 4))) __MINGW_ATTRIB_NONNULL(3)
int snprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, ...);
#if __MINGW_FORTIFY_LEVEL > 0
int __cdecl __mingw_call_vsprintf (char * __restrict__ __stream, const char * __restrict__ __format, va_list __local_argv) __MINGW_ASM_CALL(vsprintf);
int __cdecl __mingw_call_vsnprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, va_list __local_argv) __MINGW_ASM_CALL(vsnprintf);
__mingw_bos_extern_ovr
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 2, 0))) __MINGW_ATTRIB_NONNULL(3)
int vsprintf (char * __restrict__ __stream, const char * __restrict__ __format, va_list __local_argv)
{
if (__mingw_bos_known(__stream)) {
int __retval = __mingw_call_vsnprintf (__stream, __mingw_bos(__stream, 1), __format, __local_argv);
if (__retval >= 0)
__mingw_bos_ptr_chk(__stream, (size_t)__retval + 1, 1);
return __retval;
}
return __mingw_call_vsprintf(__stream, __format, __local_argv);
}
__mingw_bos_extern_ovr
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 3, 0))) __MINGW_ATTRIB_NONNULL(3)
int vsnprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, va_list __local_argv)
{
__mingw_bos_ptr_chk_warn(__stream, __n, 1);
return __mingw_call_vsnprintf (__stream, __n, __format, __local_argv);
}
#endif /* __MINGW_FORTIFY_LEVEL > 0 */
#if __MINGW_FORTIFY_VA_ARG
int __cdecl __mingw_call_sprintf (char * __restrict__ __stream, const char * __restrict__ __Format, ...) __MINGW_ASM_CALL(sprintf);
int __cdecl __mingw_call_snprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, ...) __MINGW_ASM_CALL(snprintf);
__mingw_bos_extern_ovr
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 2, 3))) __MINGW_ATTRIB_NONNULL(2)
int sprintf (char * __restrict__ __stream, const char * __restrict__ __format, ...)
{
if (__mingw_bos_known(__stream)) {
int __retval = __mingw_call_snprintf (__stream, __mingw_bos(__stream, 1), __format, __builtin_va_arg_pack());
if (__retval >= 0)
__mingw_bos_ptr_chk(__stream, (size_t)__retval + 1, 1);
return __retval;
}
return __mingw_call_sprintf (__stream, __format, __builtin_va_arg_pack());
}
__mingw_bos_extern_ovr
__attribute__((__format__ (__MINGW_PRINTF_FORMAT, 3, 4))) __MINGW_ATTRIB_NONNULL(3)
int snprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, ...)
{
__mingw_bos_ptr_chk_warn(__stream, __n, 1);
return __mingw_call_snprintf (__stream, __n, __format, __builtin_va_arg_pack());
}
#endif /* __MINGW_FORTIFY_VA_ARG */
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#else /* !_UCRT */
/* this is here to deal with software defining
* vsnprintf as _vsnprintf, eg. libxml2. */
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
#endif
__mingw_bos_ovr
__MINGW_MS_PRINTF(3, 0) __MINGW_ATTRIB_NONNULL(3)
int vsnprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, va_list __local_argv)
{
#if __MINGW_FORTIFY_LEVEL > 0
__mingw_bos_ptr_chk_warn(__stream, __n, 1);
#endif
if (__builtin_constant_p(__n) && __n == 0)
return _vscprintf(__format, __local_argv);
return __ms_vsnprintf (__stream, __n, __format, __local_argv);
}
#ifndef __NO_ISOCEXT
#if __MINGW_FORTIFY_VA_ARG
int snprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, ...) __MINGW_ASM_CALL(__ms_snprintf);
__mingw_bos_extern_ovr
__MINGW_MS_PRINTF(3, 4) __MINGW_ATTRIB_NONNULL(3)
int snprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, ...)
{
__mingw_bos_ptr_chk_warn(__stream, __n, 1);
if (__builtin_constant_p(__n) && __n == 0)
return _scprintf(__format, __builtin_va_arg_pack());
return __ms_snprintf(__stream, __n, __format, __builtin_va_arg_pack());
}
#else /* !__MINGW_FORTIFY_VA_ARG */
__mingw_ovr
__MINGW_MS_PRINTF(3, 4) __MINGW_ATTRIB_NONNULL(3)
int snprintf (char * __restrict__ __stream, size_t __n, const char * __restrict__ __format, ...)
{
int __retval;
__builtin_va_list __local_argv; __builtin_va_start( __local_argv, __format );
if (__builtin_constant_p(__n) && __n == 0)
__retval = _vscprintf(__format, __local_argv);
else
__retval = __ms_vsnprintf (__stream, __n, __format, __local_argv);
__builtin_va_end( __local_argv );
return __retval;
}
#endif /* !__MINGW_FORTIFY_VA_ARG */
#endif /* !__NO_ISOCEXT */
#if __MINGW_FORTIFY_VA_ARG
int __cdecl __mingw_call_ms_sprintf(char * __restrict__, const char * __restrict__, ...) __MINGW_ASM_CALL(sprintf);
__mingw_bos_extern_ovr
__MINGW_MS_PRINTF(2, 3) __MINGW_ATTRIB_NONNULL(2)
int sprintf (char * __restrict__ __stream, const char * __restrict__ __format, ...)
{
if (__mingw_bos_known(__stream)) {
int __retval = __ms_snprintf( __stream, __mingw_bos(__stream, 1), __format, __builtin_va_arg_pack() );
if (__retval >= 0)
__mingw_bos_ptr_chk(__stream, (size_t)__retval + 1, 1);
return __retval;
}
return __mingw_call_ms_sprintf( __stream, __format, __builtin_va_arg_pack() );
}
#endif /* __MINGW_FORTIFY_VA_ARG */
#if __MINGW_FORTIFY_LEVEL > 0
int __cdecl __mingw_call_ms_vsprintf(char * __restrict__, const char * __restrict__, va_list) __MINGW_ASM_CALL(vsprintf);
__mingw_bos_extern_ovr
__MINGW_MS_PRINTF(2, 0) __MINGW_ATTRIB_NONNULL(2)
int vsprintf (char * __restrict__ __stream, const char * __restrict__ __format, va_list __local_argv)
{
if (__mingw_bos_known(__stream)) {
int __retval = __ms_vsnprintf( __stream, __mingw_bos(__stream, 1), __format, __local_argv );
if (__retval >= 0)
__mingw_bos_ptr_chk(__stream, (size_t)__retval + 1, 1);
return __retval;
}
return __mingw_call_ms_vsprintf( __stream, __format, __local_argv );
}
#endif /* __MINGW_FORTIFY_LEVEL > 0 */
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif /* _UCRT */
#endif /* __USE_MINGW_ANSI_STDIO */
_CRTIMP int __cdecl _set_printf_count_output(int _Value);
_CRTIMP int __cdecl _get_printf_count_output(void);
#ifndef _WSTDIO_DEFINED
#define _WSTDIO_DEFINED
/* __attribute__((__format__ (gnu_wscanf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_swscanf(const wchar_t * __restrict__ _Src,const wchar_t * __restrict__ _Format,...);
/* __attribute__((__format__ (gnu_wscanf, 2, 0))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_vswscanf (const wchar_t * __restrict__ _Str,const wchar_t * __restrict__ Format,va_list argp);
/* __attribute__((__format__ (gnu_wscanf, 1, 2))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_wscanf(const wchar_t * __restrict__ _Format,...);
/* __attribute__((__format__ (gnu_wscanf, 1, 0))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_vwscanf(const wchar_t * __restrict__ Format, va_list argp);
/* __attribute__((__format__ (gnu_wscanf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_fwscanf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...);
/* __attribute__((__format__ (gnu_wscanf, 2, 0))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_vfwscanf (FILE * __restrict__ fp, const wchar_t * __restrict__ Format,va_list argp);
/* __attribute__((__format__ (gnu_wprintf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_fwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...);
/* __attribute__((__format__ (gnu_wprintf, 1, 2))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_wprintf(const wchar_t * __restrict__ _Format,...);
/* __attribute__((__format__ (gnu_wprintf, 2, 0))) */__MINGW_ATTRIB_NONNULL(2)
int __cdecl __mingw_vfwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,va_list _ArgList);
/*__attribute__((__format__ (gnu_wprintf, 1, 0))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __mingw_vwprintf(const wchar_t * __restrict__ _Format,va_list _ArgList);
/* __attribute__((__format__ (gnu_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __mingw_snwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t * __restrict__ format, ...);
/* __attribute__((__format__ (gnu_wprintf, 3, 0))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __mingw_vsnwprintf (wchar_t * __restrict__ , size_t, const wchar_t * __restrict__ , va_list);
/* __attribute__((__format__ (gnu_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __mingw_swprintf(wchar_t * __restrict__ , size_t, const wchar_t * __restrict__ , ...);
/* __attribute__((__format__ (gnu_wprintf, 3, 0))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __mingw_vswprintf(wchar_t * __restrict__ , size_t, const wchar_t * __restrict__ ,va_list);
/* __attribute__((__format__ (ms_wscanf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_swscanf(const wchar_t * __restrict__ _Src,const wchar_t * __restrict__ _Format,...)
__MINGW_UCRT_ASM_CALL(swscanf);
/* __attribute__((__format__ (ms_wscanf, 2, 0))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_vswscanf(const wchar_t * __restrict__ _Src,const wchar_t * __restrict__ _Format,va_list)
__MINGW_ASM_CALL(vswscanf);
/* __attribute__((__format__ (ms_wscanf, 1, 2))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_wscanf(const wchar_t * __restrict__ _Format,...)
__MINGW_UCRT_ASM_CALL(wscanf);
/* __attribute__((__format__ (ms_wscanf, 1, 0))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_vwscanf(const wchar_t * __restrict__ _Format, va_list)
__MINGW_ASM_CALL(vwscanf);
/* __attribute__((__format__ (ms_wscanf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_fwscanf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...)
__MINGW_UCRT_ASM_CALL(fwscanf);
/* __attribute__((__format__ (ms_wscanf, 2, 0))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_vfwscanf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,va_list)
__MINGW_ASM_CALL(vfwscanf);
/* __attribute__((__format__ (ms_wprintf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_fwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...);
/* No __MINGW_UCRT_ASM_CALL for __ms_fwprintf; this is provided as an
* actual function in the ucrt import libraries. */
/* __attribute__((__format__ (ms_wprintf, 1, 2))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_wprintf(const wchar_t * __restrict__ _Format,...)
__MINGW_UCRT_ASM_CALL(wprintf);
/* __attribute__((__format__ (ms_wprintf, 2, 0))) */__MINGW_ATTRIB_NONNULL(2)
int __cdecl __ms_vfwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,va_list _ArgList)
__MINGW_UCRT_ASM_CALL(vfwprintf);
/*__attribute__((__format__ (ms_wprintf, 1, 0))) */ __MINGW_ATTRIB_NONNULL(1)
int __cdecl __ms_vwprintf(const wchar_t * __restrict__ _Format,va_list _ArgList)
__MINGW_UCRT_ASM_CALL(vwprintf);
/* __attribute__((__format__ (ms_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __ms_swprintf(wchar_t * __restrict__ , size_t, const wchar_t * __restrict__ , ...)
__MINGW_UCRT_ASM_CALL(swprintf);
/* __attribute__((__format__ (ms_wprintf, 3, 0))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __ms_vswprintf(wchar_t * __restrict__ , size_t, const wchar_t * __restrict__ ,va_list)
__MINGW_UCRT_ASM_CALL(vswprintf);
/* __attribute__((__format__ (ms_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __ms_snwprintf(wchar_t * __restrict__ , size_t, const wchar_t * __restrict__ , ...)
__MINGW_UCRT_ASM_CALL(snwprintf);
/* __attribute__((__format__ (ms_wprintf, 3, 0))) */ __MINGW_ATTRIB_NONNULL(3)
int __cdecl __ms_vsnwprintf(wchar_t * __restrict__ , size_t, const wchar_t * __restrict__ , va_list)
__MINGW_UCRT_ASM_CALL(vsnwprintf);
#ifdef _UCRT
int __cdecl __stdio_common_vswprintf(unsigned __int64 options, wchar_t *str, size_t len, const wchar_t *format, _locale_t locale, va_list valist);
int __cdecl __stdio_common_vfwprintf(unsigned __int64 options, FILE *file, const wchar_t *format, _locale_t locale, va_list valist);
int __cdecl __stdio_common_vswscanf(unsigned __int64 options, const wchar_t *input, size_t length, const wchar_t *format, _locale_t locale, va_list valist);
int __cdecl __stdio_common_vfwscanf(unsigned __int64 options, FILE *file, const wchar_t *format, _locale_t locale, va_list valist);
#endif
#if __USE_MINGW_ANSI_STDIO && !defined(_CRTBLD)
/*
* User has expressed a preference for C99 conformance...
*/
/* __attribute__((__format__ (gnu_wscanf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int swscanf(const wchar_t *__source, const wchar_t *__format, ...)
__MINGW_ASM_CALL(__mingw_swscanf);
/* __attribute__((__format__ (gnu_wscanf, 1, 2))) */ __MINGW_ATTRIB_NONNULL(1)
int wscanf(const wchar_t *__format, ...)
__MINGW_ASM_CALL(__mingw_wscanf);
/* __attribute__((__format__ (gnu_wscanf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int fwscanf(FILE *__stream, const wchar_t *__format, ...)
__MINGW_ASM_CALL(__mingw_fwscanf);
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
/* __attribute__((__format__ (gnu_wscanf, 2, 0))) */ __MINGW_ATTRIB_NONNULL(2)
int vswscanf (const wchar_t * __restrict__ __source, const wchar_t * __restrict__ __format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vswscanf);
/* __attribute__((__format__ (gnu_wscanf, 1, 0))) */ __MINGW_ATTRIB_NONNULL(1)
int vwscanf(const wchar_t *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vwscanf);
/* __attribute__((__format__ (gnu_wscanf, 2, 0))) */ __MINGW_ATTRIB_NONNULL(2)
int vfwscanf (FILE *__stream, const wchar_t *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vfwscanf);
#endif /* __NO_ISOCEXT */
/* __attribute__((__format__ (gnu_wprintf, 2, 3))) */ __MINGW_ATTRIB_NONNULL(2)
int fwprintf (FILE *__stream, const wchar_t *__format, ...)
__MINGW_ASM_CALL(__mingw_fwprintf);
/* __attribute__((__format__ (gnu_wprintf, 1, 2))) */ __MINGW_ATTRIB_NONNULL(1)
int wprintf (const wchar_t *__format, ...)
__MINGW_ASM_CALL(__mingw_wprintf);
/* __attribute__((__format__ (gnu_wprintf, 2, 0))) */ __MINGW_ATTRIB_NONNULL(2)
int vfwprintf (FILE *__stream, const wchar_t *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vfwprintf);
/* __attribute__((__format__ (gnu_wprintf, 1, 0))) */ __MINGW_ATTRIB_NONNULL(1)
int vwprintf (const wchar_t *__format, __builtin_va_list __local_argv)
__MINGW_ASM_CALL(__mingw_vwprintf);
/* __attribute__((__format__ (gnu_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int swprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, ...)
__MINGW_ASM_CALL(__mingw_swprintf);
#if __MINGW_FORTIFY_VA_ARG
__mingw_bos_extern_ovr
/* __attribute__((__format__ (gnu_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int swprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, ...)
{
__mingw_bos_ptr_chk_warn(__stream, __n * sizeof(wchar_t), 1);
return __mingw_swprintf( __stream, __n, __format, __builtin_va_arg_pack() );
}
#endif /* __MINGW_FORTIFY_VA_ARG */
__mingw_bos_ovr
/* __attribute__((__format__ (gnu_wprintf, 3, 0))) */ __MINGW_ATTRIB_NONNULL(3)
int vswprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, __builtin_va_list __local_argv)
{
#if __MINGW_FORTIFY_LEVEL > 0
__mingw_bos_ptr_chk_warn(__stream, __n * sizeof(wchar_t), 1);
#endif
return __mingw_vswprintf( __stream, __n, __format, __local_argv );
}
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
/* __attribute__((__format__ (gnu_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int snwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, ...)
__MINGW_ASM_CALL(__mingw_snwprintf);
#if __MINGW_FORTIFY_VA_ARG
__mingw_bos_extern_ovr
/* __attribute__((__format__ (gnu_wprintf, 3, 4))) */ __MINGW_ATTRIB_NONNULL(3)
int snwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, ...)
{
__mingw_bos_ptr_chk_warn(__stream, __n * sizeof(wchar_t), 1);
return __mingw_snwprintf( __stream, __n, __format, __builtin_va_arg_pack() );
}
#endif /* __MINGW_FORTIFY_VA_ARG */
__mingw_bos_ovr
/* __attribute__((__format__ (gnu_wprintf, 3, 0))) */ __MINGW_ATTRIB_NONNULL(3)
int vsnwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, __builtin_va_list __local_argv)
{
#if __MINGW_FORTIFY_LEVEL > 0
__mingw_bos_ptr_chk_warn(__stream, __n * sizeof(wchar_t), 1);
#endif
return __mingw_vsnwprintf( __stream, __n, __format, __local_argv );
}
#endif /* __NO_ISOCEXT */
#else /* !__USE_MINGW_ANSI_STDIO */
#ifdef _UCRT
__MINGW_ATTRIB_DEPRECATED_SEC_WARN
int __cdecl fwscanf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...);
__MINGW_ATTRIB_DEPRECATED_SEC_WARN
int __cdecl swscanf(const wchar_t * __restrict__ _Src,const wchar_t * __restrict__ _Format,...);
__MINGW_ATTRIB_DEPRECATED_SEC_WARN
int __cdecl wscanf(const wchar_t * __restrict__ _Format,...);
__MINGW_ATTRIB_NONNULL(2)
int __cdecl vfwscanf(FILE *__stream, const wchar_t *__format, va_list __local_argv);
__MINGW_ATTRIB_NONNULL(2)
int __cdecl vswscanf(const wchar_t * __restrict__ __source, const wchar_t * __restrict__ __format, va_list __local_argv);
__MINGW_ATTRIB_NONNULL(1)
int __cdecl vwscanf(const wchar_t *__format, va_list __local_argv);
int __cdecl fwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...);
int __cdecl wprintf(const wchar_t * __restrict__ _Format,...);
int __cdecl vfwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,va_list _ArgList);
int __cdecl vwprintf(const wchar_t * __restrict__ _Format,va_list _ArgList);
#else
int __cdecl fwscanf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
int __cdecl swscanf(const wchar_t * __restrict__ _Src,const wchar_t * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
int __cdecl wscanf(const wchar_t * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
__MINGW_ATTRIB_NONNULL(2)
int vfwscanf (FILE *__stream, const wchar_t *__format, __builtin_va_list __local_argv);
__MINGW_ATTRIB_NONNULL(2)
int vswscanf (const wchar_t * __restrict__ __source, const wchar_t * __restrict__ __format, __builtin_va_list __local_argv);
__MINGW_ATTRIB_NONNULL(1)
int vwscanf(const wchar_t *__format, __builtin_va_list __local_argv);
#endif /* __NO_ISOCEXT */
int __cdecl fwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,...);
int __cdecl wprintf(const wchar_t * __restrict__ _Format,...);
int __cdecl vfwprintf(FILE * __restrict__ _File,const wchar_t * __restrict__ _Format,va_list _ArgList);
int __cdecl vwprintf(const wchar_t * __restrict__ _Format,va_list _ArgList);
#endif /* _UCRT */
int __cdecl swprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t * __restrict__ _Format,...);
int __cdecl vswprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t * __restrict__ _Format,va_list _Args);
int __cdecl snwprintf(wchar_t * __restrict__ s, size_t n, const wchar_t * __restrict__ format, ...);
int __cdecl vsnwprintf(wchar_t * __restrict__ s, size_t n, const wchar_t * __restrict__ format, va_list arg);
#endif /* __USE_MINGW_ANSI_STDIO */
#ifndef WEOF
#define WEOF (wint_t)(0xFFFF)
#endif
#ifdef _POSIX_
_CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode);
#else
_CRTIMP FILE *__cdecl _wfsopen(const wchar_t *_Filename,const wchar_t *_Mode,int _ShFlag);
#endif
wint_t __cdecl fgetwc(FILE *_File);
_CRTIMP wint_t __cdecl _fgetwchar(void);
wint_t __cdecl fputwc(wchar_t _Ch,FILE *_File);
_CRTIMP wint_t __cdecl _fputwchar(wchar_t _Ch);
wint_t __cdecl getwc(FILE *_File);
wint_t __cdecl getwchar(void);
wint_t __cdecl putwc(wchar_t _Ch,FILE *_File);
wint_t __cdecl putwchar(wchar_t _Ch);
wint_t __cdecl ungetwc(wint_t _Ch,FILE *_File);
wchar_t *__cdecl fgetws(wchar_t * __restrict__ _Dst,int _SizeInWords,FILE * __restrict__ _File);
int __cdecl fputws(const wchar_t * __restrict__ _Str,FILE * __restrict__ _File);
_CRTIMP wchar_t *__cdecl _getws(wchar_t *_String) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl _putws(const wchar_t *_Str);
_CRTIMP int __cdecl _scwprintf(const wchar_t * __restrict__ _Format,...);
#ifndef _UCRT
_CRTIMP int __cdecl _swprintf_c(wchar_t * __restrict__ _DstBuf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,...);
_CRTIMP int __cdecl _vswprintf_c(wchar_t * __restrict__ _DstBuf,size_t _SizeInWords,const wchar_t * __restrict__ _Format,va_list _ArgList);
#endif /* _UCRT */
_CRTIMP int __cdecl _snwprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t * __restrict__ _Format,...) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl _vsnwprintf(wchar_t * __restrict__ _Dest,size_t _Count,const wchar_t * __restrict__ _Format,va_list _Args) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP int __cdecl _vscwprintf(const wchar_t * __restrict__ _Format,va_list _ArgList);
_CRTIMP int __cdecl _swprintf(wchar_t * __restrict__ _Dest,const wchar_t * __restrict__ _Format,...);
_CRTIMP int __cdecl _vswprintf(wchar_t * __restrict__ _Dest,const wchar_t * __restrict__ _Format,va_list _Args);
#ifndef RC_INVOKED
#include <swprintf.inl>
#endif
#ifdef _CRT_NON_CONFORMING_SWPRINTFS
#ifndef __cplusplus
#define _swprintf_l __swprintf_l
#define _vswprintf_l __vswprintf_l
#endif
#endif
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("_wtempnam")
#undef _wtempnam
#endif
_CRTIMP wchar_t *__cdecl _wtempnam(const wchar_t *_Directory,const wchar_t *_FilePrefix);
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("_wtempnam")
#endif
_CRTIMP int __cdecl _snwscanf(const wchar_t * __restrict__ _Src,size_t _MaxCount,const wchar_t * __restrict__ _Format,...);
_CRTIMP FILE *__cdecl _wfdopen(int _FileHandle ,const wchar_t *_Mode);
_CRTIMP FILE *__cdecl _wfopen(const wchar_t * __restrict__ _Filename,const wchar_t *__restrict__ _Mode) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
_CRTIMP FILE *__cdecl _wfreopen(const wchar_t * __restrict__ _Filename,const wchar_t * __restrict__ _Mode,FILE * __restrict__ _OldFile) __MINGW_ATTRIB_DEPRECATED_SEC_WARN;
#ifndef _CRT_WPERROR_DEFINED
#define _CRT_WPERROR_DEFINED
_CRTIMP void __cdecl _wperror(const wchar_t *_ErrMsg);
#endif
_CRTIMP FILE *__cdecl _wpopen(const wchar_t *_Command,const wchar_t *_Mode);
#if !defined(NO_OLDNAMES) && !defined(wpopen)
#define wpopen _wpopen
#endif
_CRTIMP int __cdecl _wremove(const wchar_t *_Filename);
_CRTIMP wchar_t *__cdecl _wtmpnam(wchar_t *_Buffer);
#if __MSVCRT_VERSION__ >= 0x800
_CRTIMP wint_t __cdecl _fgetwc_nolock(FILE *_File);
_CRTIMP wint_t __cdecl _fputwc_nolock(wchar_t _Ch,FILE *_File);
_CRTIMP wint_t __cdecl _ungetwc_nolock(wint_t _Ch,FILE *_File);
#endif
#undef _CRT_GETPUTWCHAR_NOINLINE
#if !defined(__cplusplus) || defined(_CRT_GETPUTWCHAR_NOINLINE) || defined (__CRT__NO_INLINE)
#define getwchar() fgetwc(stdin)
#define putwchar(_c) fputwc((_c),stdout)
#else
__CRT_INLINE wint_t __cdecl getwchar() {return (fgetwc(stdin)); }
__CRT_INLINE wint_t __cdecl putwchar(wchar_t _C) {return (fputwc(_C,stdout)); }
#endif
#define getwc(_stm) fgetwc(_stm)
#define putwc(_c,_stm) fputwc(_c,_stm)
#if __MSVCRT_VERSION__ >= 0x800
#define _putwc_nolock(_c,_stm) _fputwc_nolock(_c,_stm)
#define _getwc_nolock(_c) _fgetwc_nolock(_c)
#endif
#endif
#define _STDIO_DEFINED
#endif
#ifdef _UCRT
_CRTIMP int __cdecl _fgetc_nolock(FILE *_File);
_CRTIMP int __cdecl _fputc_nolock(int _Char, FILE *_File);
_CRTIMP int __cdecl _getc_nolock(FILE *_File);
_CRTIMP int __cdecl _putc_nolock(int _Char, FILE *_File);
#else
#define _fgetc_nolock(_stream) (--(_stream)->_cnt >= 0 ? 0xff & *(_stream)->_ptr++ : _filbuf(_stream))
#define _fputc_nolock(_c,_stream) (--(_stream)->_cnt >= 0 ? 0xff & (*(_stream)->_ptr++ = (char)(_c)) : _flsbuf((_c),(_stream)))
#define _getc_nolock(_stream) _fgetc_nolock(_stream)
#define _putc_nolock(_c,_stream) _fputc_nolock(_c,_stream)
#endif
#define _getchar_nolock() _getc_nolock(stdin)
#define _putchar_nolock(_c) _putc_nolock((_c),stdout)
#define _getwchar_nolock() _getwc_nolock(stdin)
#define _putwchar_nolock(_c) _putwc_nolock((_c),stdout)
_CRTIMP void __cdecl _lock_file(FILE *_File);
_CRTIMP void __cdecl _unlock_file(FILE *_File);
#if __MSVCRT_VERSION__ >= 0x800
_CRTIMP int __cdecl _fclose_nolock(FILE *_File);
_CRTIMP int __cdecl _fflush_nolock(FILE *_File);
_CRTIMP size_t __cdecl _fread_nolock(void * __restrict__ _DstBuf,size_t _ElementSize,size_t _Count,FILE * __restrict__ _File);
_CRTIMP int __cdecl _fseek_nolock(FILE *_File,long _Offset,int _Origin);
_CRTIMP long __cdecl _ftell_nolock(FILE *_File);
__MINGW_EXTENSION _CRTIMP int __cdecl _fseeki64_nolock(FILE *_File,__int64 _Offset,int _Origin);
__MINGW_EXTENSION _CRTIMP __int64 __cdecl _ftelli64_nolock(FILE *_File);
_CRTIMP size_t __cdecl _fwrite_nolock(const void * __restrict__ _DstBuf,size_t _Size,size_t _Count,FILE * __restrict__ _File);
_CRTIMP int __cdecl _ungetc_nolock(int _Ch,FILE *_File);
#endif
#if !defined(NO_OLDNAMES) || !defined(_POSIX)
#define P_tmpdir _P_tmpdir
#define SYS_OPEN _SYS_OPEN
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma push_macro("tempnam")
#undef tempnam
#endif
char *__cdecl tempnam(const char *_Directory,const char *_FilePrefix) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#if defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
#pragma pop_macro("tempnam")
#endif
int __cdecl fcloseall(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
FILE *__cdecl fdopen(int _FileHandle,const char *_Format) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
int __cdecl fgetchar(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
int __cdecl fileno(FILE *_File) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
int __cdecl flushall(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
int __cdecl fputchar(int _Ch) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
int __cdecl getw(FILE *_File) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
int __cdecl putw(int _Ch,FILE *_File) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
int __cdecl rmtmp(void) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
#endif
#ifndef __MINGW_MBWC_CONVERT_DEFINED
#define __MINGW_MBWC_CONVERT_DEFINED
/**
* __mingw_str_wide_utf8
* Converts a null terminated UCS-2 string to a multibyte (UTF-8) equivalent.
* Caller is supposed to free allocated buffer with __mingw_str_free().
* @param[in] wptr Pointer to wide string.
* @param[out] mbptr Pointer to multibyte string.
* @param[out] buflen Optional parameter for length of allocated buffer.
* @return Number of characters converted, 0 for failure.
*
* WideCharToMultiByte - http://msdn.microsoft.com/en-us/library/dd374130(VS.85).aspx
*/
int __cdecl __mingw_str_wide_utf8 (const wchar_t * const wptr, char **mbptr, size_t * buflen);
/**
* __mingw_str_utf8_wide
* Converts a null terminated UTF-8 string to a UCS-2 equivalent.
* Caller is supposed to free allocated buffer with __mingw_str_free().
* @param[out] mbptr Pointer to multibyte string.
* @param[in] wptr Pointer to wide string.
* @param[out] buflen Optional parameter for length of allocated buffer.
* @return Number of characters converted, 0 for failure.
*
* MultiByteToWideChar - http://msdn.microsoft.com/en-us/library/dd319072(VS.85).aspx
*/
int __cdecl __mingw_str_utf8_wide (const char *const mbptr, wchar_t ** wptr, size_t * buflen);
/**
* __mingw_str_free
* Frees buffer create by __mingw_str_wide_utf8 and __mingw_str_utf8_wide.
* @param[in] ptr memory block to free.
*
*/
void __cdecl __mingw_str_free(void *ptr);
#endif /* __MINGW_MBWC_CONVERT_DEFINED */
#ifdef _CRT_USE_WINAPI_FAMILY_DESKTOP_APP
#ifndef _WSPAWN_DEFINED
#define _WSPAWN_DEFINED
_CRTIMP intptr_t __cdecl _wspawnl(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...);
_CRTIMP intptr_t __cdecl _wspawnle(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...);
_CRTIMP intptr_t __cdecl _wspawnlp(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...);
_CRTIMP intptr_t __cdecl _wspawnlpe(int _Mode,const wchar_t *_Filename,const wchar_t *_ArgList,...);
_CRTIMP intptr_t __cdecl _wspawnv(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList);
_CRTIMP intptr_t __cdecl _wspawnve(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env);
_CRTIMP intptr_t __cdecl _wspawnvp(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList);
_CRTIMP intptr_t __cdecl _wspawnvpe(int _Mode,const wchar_t *_Filename,const wchar_t *const *_ArgList,const wchar_t *const *_Env);
#endif
#ifndef _P_WAIT
#define _P_WAIT 0
#define _P_NOWAIT 1
#define _OLD_P_OVERLAY 2
#define _P_NOWAITO 3
#define _P_DETACH 4
#define _P_OVERLAY 2
#define _WAIT_CHILD 0
#define _WAIT_GRANDCHILD 1
#endif
#ifndef _SPAWNV_DEFINED
#define _SPAWNV_DEFINED
_CRTIMP intptr_t __cdecl _spawnv(int _Mode,const char *_Filename,const char *const *_ArgList);
_CRTIMP intptr_t __cdecl _spawnve(int _Mode,const char *_Filename,const char *const *_ArgList,const char *const *_Env);
_CRTIMP intptr_t __cdecl _spawnvp(int _Mode,const char *_Filename,const char *const *_ArgList);
_CRTIMP intptr_t __cdecl _spawnvpe(int _Mode,const char *_Filename,const char *const *_ArgList,const char *const *_Env);
#endif
#endif /* _CRT_USE_WINAPI_FAMILY_DESKTOP_APP */
#ifdef __cplusplus
}
#endif
#pragma pop_macro("snprintf")
#pragma pop_macro("vsnprintf")
#pragma pop_macro("snwprintf")
#pragma pop_macro("vsnwprintf")
#pragma pack(pop)
#include <sec_api/stdio_s.h>
#endif
int main() {
printf("hello world\n");
return 0;
}
第二阶段:编译 Compilation
转换:hello.i
→ hello.s
(文本文件)
核心工作:
- 将 C 代码翻译为目标架构的汇编代码
- 进行语法分析、语义分析
- 执行代码优化
输出示例(hello.s
,基于x86-64,调用printf
):
section .data
message db "hello world", 10
message_len equ $ - message
section .text
global _start
_start:
mov rax, 1
mov rdi, 1
mov rsi, message
mov rdx, message_len
syscall
mov rax, 60
mov rdi, 0
syscall
第三阶段:汇编 Assembly
转换:hello.s
→ hello.o
(二进制文件)
核心工作:汇编器将hello.s
转换为机器码,生成可重定位目标文件hello.o
,包含二进制指令和符号表。
输出示例(hello.o
的十六进制转储):
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00 00 00 10 64 86 07 00 00 00 00 00 F0 01 00 00
00 00 00 20 00 00 00 2E 74 65 78 74 00 00 00 00
00 00 00 30 00 00 00 00 03 00 00 00 2C 00 50 62
00 00 00 40 61 00 00 00 00 00 00 00 00 00 00 00
00 00 00 50 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 60 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 70 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 80 00 00 00 00 00 00 80 00 50 C2 E7 64
00 00 00 90 74 61 00 00 00 00 00 00 00 00 00 00
00 00 00 A0 5C 01 00 00 00 00 00 00 00 00 00 00
00 00 00 B0 00 00 00 00 0C 00 00 00 00 00 00 00
00 00 00 C0 00 00 00 00 00 00 40 00 30 42 E7 64
00 00 00 D0 74 61 00 00 00 00 00 00 00 00 00 00
00 00 00 E0 78 01 00 00 02 01 00 00 00 00 00 00
00 00 00 F0 40 00 30 2F 34 00 00 00 00 00 00 00
00 00 01 00 00 00 00 30 00 00 84 01 00 00 00 00
00 00 01 10 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 20 00 00 00 00 00 00 40 00 50 46 55 48
00 00 01 30 48 83 EC 20 E8 00 00 00 48 8D 05 00
00 00 01 40 48 89 C1 E8 00 00 00 B8 00 00 48 83
00 00 01 50 20 5D C3 90 90 90 90 90 90 90 90 90
00 00 01 60 6F 29 77 6F 72 6C 64 00 00 01 08 03
00 00 01 70 08 32 04 03 01 50 00 00 00 00 00 27
00 00 01 80 00 00 00 00 47 43 43 3A 20 28 52 52
00 00 01 90 42 75 69 6C 64 29 20 28 47 43 43 20
00 00 01 A0 72 46 6A 65 74 74 79 29 20 31 35 2E
00 00 01 B0 32 20 30 00 13 39 00 00 04 00 10 00
00 00 01 C0 00 00 0A 00 00 00 04 18 00 00 12 00
00 00 01 D0 04 00 00 00 00 00 04 00 00 00 03 00
00 00 01 E0 04 00 00 00 03 00 00 00 00 00 03 00
00 00 01 F0 2E 66 69 6C 65 00 00 00 00 00 FE FF
00 00 02 00 67 01 86 65 6C 6C 6F 20 00 00 00 00
00 00 02 10 00 00 00 00 6D 61 69 6E 00 00 00 00
00 00 02 20 01 00 20 00 02 01 00 00 00 00 00 00
00 00 02 30 00 00 00 00 00 00 00 2E 74 65 78 74
00 00 02 40 00 00 00 00 01 00 00 00 00 00 00 00
00 00 02 50 00 00 00 00 00 00 00 00 00 00 00 00
00 00 02 60 00 00 00 00 00 00 00 00 00 00 00 00
00 00 02 70 00 00 00 00 00 00 00 00 00 00 00 00
00 00 02 80 2E 72 65 6C 2E 74 65 78 74 00 00 00
00 00 02 90 74 61 00 00 00 00 00 00 00 00 00 00
00 00 02 A0 7A 01 00 00 02 01 00 00 00 00 00 00
00 00 02 B0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 02 C0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 02 D0 00 00 00 00 05 00 00 00 00 00 00 00
00 00 02 E0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 02 F0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 10 00 00 00 0F 00 00 00 00 00 00 07 00
00 00 03 20 03 01 2B 00 00 00 00 00 00 00 00 00
00 00 03 30 00 00 00 00 00 00 00 1A 00 00 00 00
00 00 03 40 00 00 00 00 02 00 5F 6D 61 69 6E 00
00 00 03 50 00 00 00 00 20 02 00 00 29 00 00 2E
00 00 03 60 74 65 78 74 00 00 00 00 00 00 00 00
00 00 03 70 74 61 00 00 00 00 00 00 00 00 00 00
00 00 03 80 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 90 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 A0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 B0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 C0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 D0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 E0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 03 F0 00 00 00 00 00 00 00 00 00 00 00 00
第四阶段:链接 Linking
转换:hello.o
+ 库文件 → hello.exe
(二进制文件)
过程:链接器将hello.o
与标准库的printf.o
等目标文件合并,解析符号地址,生成可执行文件hello.exe
。
输出示例(hello.exe
的十六进制转储,部分):
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00 00 00 00 4D 5A 90 00 03 00 00 00 04 00 00 00
00 00 00 10 B8 00 00 00 00 00 00 40 00 00 00 00
00 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 30 00 00 00 00 00 00 00 00 80 00 00 00
00 00 00 40 0E 1F BA 0E 00 B4 09 CD 21 B8 01 4C
00 00 00 50 69 73 20 70 72 67 72 61 6D 20 63 61
00 00 00 60 6E 6E 6F 74 20 62 65 20 72 75 6E 20
00 00 00 70 69 6E 20 44 4F 53 20 6D 6F 64 65 2E
00 00 00 80 50 45 00 00 4C 01 04 00 5B 90 83 4B
00 00 00 90 00 00 00 00 00 00 00 00 E0 00 0E 21
00 00 00 A0 0B 01 00 00 00 10 00 00 00 20 00 00
00 00 00 B0 00 00 40 00 00 00 00 00 00 00 00 00
00 00 00 C0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 D0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 E0 00 00 00 00 10 00 00 00 00 00 00 00
00 00 00 F0 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 10 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 20 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 30 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 40 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 50 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 60 00 00 00 00 00 00 00 00 00 00 00 00
00 00 01 70 00 00 00 00 00 00 00 00 00 00 00 00
…………
00 00 01 80 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 01 90 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 01 A0 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 01 B0 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 01 C0 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 01 D0 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 01 E0 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 01 F0 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 02 00 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 10 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 02 20 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 30 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 02 40 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 50 52 54 5F 24 5F 36 30 30 37 77 30 5F
00 00 02 60 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 70 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 02 80 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 90 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 02 A0 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 B0 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 02 C0 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 D0 52 54 5F 24 5F 36 30 30 37 37 30 5F
00 00 02 E0 5F 5F 78 5F 5F 49 41 54 5F 53 54 41
00 00 02 F0 52 54 5F 24 5F 36 30 30 37 77 30 5F
硬件
关键概念
总线 Bus
物理位置:总线以主板上的电路或芯片组(如南桥、北桥或现代的平台控制器集线器PCH)形式存在,连接CPU、内存、存储设备、扩展卡(如显卡、声卡)等组件。
总线标准:
- PCIe:GPU、声卡、网卡、SSD……
- 内存总线
- USB:通用串行总线
- SATA 总线
I/O设备(I:input | O:output)
- INPUT:键盘、鼠标、麦克风
- OUTPUT:显示器、打印机、扬声器
- INPUT\OUTPUT:硬盘、网卡、触摸屏
主存 RAM 随机存取存储器
主存的特点:
- 易失性:断电后数据丢失
- 随机访问:可以直接访问任意地址的数据
- 线性地址空间:每个字节都有唯一的地址
DRAM技术:现代主存主要采用动态随机存取存储器(DRAM),需要定期刷新以保持数据。
中央处理器 CPU
物理位置:
- 通过内存总线连接RAM
- 通过PCIe总线连接GPU等扩展卡
- 通过系统总线连接南桥/北桥或PCH
CPU的核心组件:ALU、寄存器、PC、高速缓存等
CPU的基本操作:
- 加载:从主存读取指令,放到寄存器
- 储存:从寄存器写入主存
- 操作:通过 ALU 对寄存器的两个字做算术运算,返回结果到寄存器
- 跳转:从指令本身抽取一个字,复制到 PC 中
高速缓存 Cache
由于现代CPU速度极快,主存会拖慢CPU的速度,所以诞生了高速缓存来弥补这个速度差异。
分级架构:
- L1缓存:速度最快,容量最小(数万字节)
- L2缓存:速度中等,容量中等(数十万到数百万字节)
- L3缓存:速度相对较慢,容量最大(数十、数百MB)
Intel现在都配备了L3缓存,AMD的X3D CPU可以配备很大的L3。
工作原理:基于局部性原理,将CPU可能频繁访问的数据预先存储在高速缓存中,避免每次都从较慢的主存中读取。
性能影响:合理利用高速缓存可以让程序性能提升一个数量级,这也是为什么现代CPU设计中缓存容量越来越大的原因。
一个典型系统的硬件组成
这张图展示了一个典型计算机系统的硬件架构,各个组件通过总线系统相互连接,形成一个有机的整体。
运行程序
第一步:系统检测命令
当用户在终端输入 ./hello
时,操作系统的命令解释器(shell)开始工作:
- 解析命令行参数
- 定位可执行文件
- 准备创建新进程
第二步:程序加载
操作系统执行以下步骤:
- 从存储设备读取可执行文件
- 将程序代码和数据加载到主存
- 为程序分配内存空间
- 设置程序运行环境
第三步:程序执行
CPU开始执行程序:
- 从主存读取指令
- 解码并执行指令
- 调用系统函数(如
printf
) - 将结果输出到终端
存储设备层次结构
现代计算机系统采用层次化存储结构,平衡了速度、容量和成本的关系。
总结
下一篇将继续漫游计算机系统,探讨进程、线程、并发和并行等。