C语言15大头文件介绍&&crt0.c代码内容解释和编译器构造
C89(标准C) 有15个头文件 ,这些头文件包含了标准库的函数的声明
1. assert.h
/* assert.h
assert macro
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
void _Cdecl __assertfail(char *__msg, char *__cond,
char *__file, int __line);
#ifdef __cplusplus
}
#endif
#undef assert
#ifdef NDEBUG
# define assert(p) ((void)0)
#else
# define _ENDL "\n"
# define assert(p) ((p) ? (void)0 : (void) __assertfail( \
"Assertion failed: %s, file %s, line %d" _ENDL, \
#p, __FILE__, __LINE__ ) )
#endif
2. float.h
/* float.h
Defines implementation specific macros for dealing with
floating point.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __FLOAT_H
#define __FLOAT_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#define FLT_RADIX 2
#define FLT_ROUNDS 1
#define FLT_GUARD 1
#define FLT_NORMALIZE 1
#define DBL_DIG 15
#define FLT_DIG 6
#define LDBL_DIG 19
#define DBL_MANT_DIG 53
#define FLT_MANT_DIG 24
#define LDBL_MANT_DIG 64
#define DBL_EPSILON 2.2204460492503131E-16
#define FLT_EPSILON 1.19209290E-07F
#define LDBL_EPSILON 1.084202172485504E-19
/* smallest positive IEEE normal numbers */
#define DBL_MIN 2.2250738585072014E-308
#define FLT_MIN 1.17549435E-38F
#define LDBL_MIN _tiny_ldble
#define DBL_MAX _huge_dble
#define FLT_MAX _huge_flt
#define LDBL_MAX _huge_ldble
#define DBL_MAX_EXP +1024
#define FLT_MAX_EXP +128
#define LDBL_MAX_EXP +16384
#define DBL_MAX_10_EXP +308
#define FLT_MAX_10_EXP +38
#define LDBL_MAX_10_EXP +4932
#define DBL_MIN_10_EXP -307
#define FLT_MIN_10_EXP -37
#define LDBL_MIN_10_EXP -4931
#define DBL_MIN_EXP -1021
#define FLT_MIN_EXP -125
#define LDBL_MIN_EXP -16381
extern float _Cdecl _huge_flt;
extern double _Cdecl _huge_dble;
extern long double _Cdecl _huge_ldble;
extern long double _Cdecl _tiny_ldble;
#ifdef __cplusplus
extern "C" {
#endif
unsigned int _Cdecl _clear87(void);
unsigned int _Cdecl _control87(unsigned int __newcw, unsigned int __mask);
void _Cdecl _fpreset(void);
unsigned int _Cdecl _status87(void);
#ifdef __cplusplus
}
#endif
#if !__STDC__
/* 8087/80287 Status Word format */
#define SW_INVALID 0x0001 /* Invalid operation */
#define SW_DENORMAL 0x0002 /* Denormalized operand */
#define SW_ZERODIVIDE 0x0004 /* Zero divide */
#define SW_OVERFLOW 0x0008 /* Overflow */
#define SW_UNDERFLOW 0x0010 /* Underflow */
#define SW_INEXACT 0x0020 /* Precision (Inexact result) */
/* 8087/80287 Control Word format */
#define MCW_EM 0x003f /* interrupt Exception Masks*/
#define EM_INVALID 0x0001 /* invalid */
#define EM_DENORMAL 0x0002 /* denormal */
#define EM_ZERODIVIDE 0x0004 /* zero divide */
#define EM_OVERFLOW 0x0008 /* overflow */
#define EM_UNDERFLOW 0x0010 /* underflow */
#define EM_INEXACT 0x0020 /* inexact (precision) */
#define MCW_IC 0x1000 /* Infinity Control */
#define IC_AFFINE 0x1000 /* affine */
#define IC_PROJECTIVE 0x0000 /* projective */
#define MCW_RC 0x0c00 /* Rounding Control */
#define RC_CHOP 0x0c00 /* chop */
#define RC_UP 0x0800 /* up */
#define RC_DOWN 0x0400 /* down */
#define RC_NEAR 0x0000 /* near */
#define MCW_PC 0x0300 /* Precision Control */
#define PC_24 0x0000 /* 24 bits */
#define PC_53 0x0200 /* 53 bits */
#define PC_64 0x0300 /* 64 bits */
/* 8087/80287 Initial Control Word */
/* use affine infinity, mask underflow and precision exceptions */
#define CW_DEFAULT _default87
extern unsigned int _Cdecl _default87;
/*
SIGFPE signal error types (for integer & float exceptions).
*/
#define FPE_INTOVFLOW 126 /* 80x86 Interrupt on overflow */
#define FPE_INTDIV0 127 /* 80x86 Integer divide by zero */
#define FPE_INVALID 129 /* 80x87 invalid operation */
#define FPE_ZERODIVIDE 131 /* 80x87 divide by zero */
#define FPE_OVERFLOW 132 /* 80x87 arithmetic overflow */
#define FPE_UNDERFLOW 133 /* 80x87 arithmetic underflow */
#define FPE_INEXACT 134 /* 80x87 precision loss */
#define FPE_STACKFAULT 135 /* 80x87 stack overflow */
#define FPE_EXPLICITGEN 140 /* When SIGFPE is raise()'d */
/*
SIGSEGV signal error types.
*/
#define SEGV_BOUND 10 /* A BOUND violation (SIGSEGV) */
#define SEGV_EXPLICITGEN 11 /* When SIGSEGV is raise()'d */
/*
SIGILL signal error types.
*/
#define ILL_EXECUTION 20 /* Illegal operation exception */
#define ILL_EXPLICITGEN 21 /* When SIGILL is raise()'d */
#endif /* !__STDC__ */
#endif
3. math.h
/* math.h
Definitions for the math floating point package.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __MATH_H
#define __MATH_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#define HUGE_VAL _huge_dble
extern double _Cdecl _huge_dble;
#define _LHUGE_VAL _huge_ldble
extern long double _Cdecl _huge_ldble;
#ifdef __cplusplus
extern "C" {
#endif
double _Cdecl acos (double __x);
double _Cdecl asin (double __x);
double _Cdecl atan (double __x);
double _Cdecl atan2 (double __y, double __x);
double _Cdecl ceil (double __x);
double _Cdecl cos (double __x);
double _Cdecl cosh (double __x);
double _Cdecl exp (double __x);
double _Cdecl fabs (double __x);
double _Cdecl __fabs__ (double __x); /* Intrinsic */
double _Cdecl floor (double __x);
double _Cdecl fmod (double __x, double __y);
double _Cdecl frexp (double __x, int *__exponent);
double _Cdecl ldexp (double __x, int __exponent);
double _Cdecl log (double __x);
double _Cdecl log10 (double __x);
double _Cdecl modf (double __x, double *__ipart);
double _Cdecl pow (double __x, double __y);
double _Cdecl sin (double __x);
double _Cdecl sinh (double __x);
double _Cdecl sqrt (double __x);
double _Cdecl tan (double __x);
double _Cdecl tanh (double __x);
long double _Cdecl acosl (long double __x);
long double _Cdecl asinl (long double __x);
long double _Cdecl atan2l (long double __x, long double __y);
long double _Cdecl atanl (long double __x);
long double _Cdecl ceill (long double __x);
long double _Cdecl coshl (long double __x);
long double _Cdecl cosl (long double __x);
long double _Cdecl expl (long double __x);
long double _Cdecl fabsl (long double __x);
long double _Cdecl floorl (long double __x);
long double _Cdecl fmodl (long double __x, long double __y);
long double _Cdecl frexpl (long double __x, int *__exponent);
long double _Cdecl ldexpl (long double __x, int __exponent);
long double _Cdecl log10l (long double __x);
long double _Cdecl logl (long double __x);
long double _Cdecl modfl (long double __x, long double *__ipart);
long double _Cdecl powl (long double __x, long double __y);
long double _Cdecl sinhl (long double __x);
long double _Cdecl sinl (long double __x);
long double _Cdecl sqrtl (long double __x);
long double _Cdecl tanhl (long double __x);
long double _Cdecl tanl (long double __x);
typedef enum
{
DOMAIN = 1, /* argument domain error -- log (-1) */
SING, /* argument singularity -- pow (0,-2)) */
OVERFLOW, /* overflow range error -- exp (1000) */
UNDERFLOW, /* underflow range error -- exp (-1000) */
TLOSS, /* total loss of significance -- sin(10e70) */
PLOSS, /* partial loss of signif. -- not used */
STACKFAULT /* floating point unit stack overflow */
} _mexcep;
#ifdef __cplusplus
}
#endif
#if !__STDC__
struct exception
{
int type;
char *name;
double arg1, arg2, retval;
};
struct _exceptionl
{
int type;
char *name;
long double arg1, arg2, retval;
};
#ifdef __cplusplus
extern "C" {
#endif
int _Cdecl abs (int __x);
double _Cdecl atof (const char *__s);
double _Cdecl hypot (double __x, double __y);
long _Cdecl labs (long __x);
int _Cdecl matherr (struct exception *__e);
double _Cdecl poly (double __x, int __degree, double *__coeffs);
double _Cdecl pow10 (int __p);
int _Cdecl _matherrl (struct _exceptionl *__e);
long double _Cdecl _atold (const char *__s);
long double _Cdecl hypotl (long double __x, long double __y);
long double _Cdecl polyl (long double __x, int __degree, long double *__coeffs);
long double _Cdecl pow10l (int __p);
#ifdef __cplusplus
/* use class complex instead of cabs in C++ */
#else
struct complex /* as used by "cabs" function */
{
double x, y;
};
struct _complexl /* as used by "cabsl" function */
{
long double x, y;
};
#define cabs(z) (hypot ((z).x, (z).y))
#define cabsl(z) (hypotl ((z).x, (z).y))
#endif
#ifdef __cplusplus
}
#endif
/* Constants rounded for 21 decimals. */
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
#define M_LN2 0.693147180559945309417
#define M_LN10 2.30258509299404568402
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923
#define M_PI_4 0.785398163397448309616
#define M_1_PI 0.318309886183790671538
#define M_2_PI 0.636619772367581343076
#define M_1_SQRTPI 0.564189583547756286948
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT_2 0.707106781186547524401
#define EDOM 33 /* Math argument */
#define ERANGE 34 /* Result too large */
#endif /* !__STDC__ */
#endif
--------------------------------------------------------
4.stdarg.h
/* stdarg.h
Definitions for accessing parameters in functions that accept
a variable number of arguments.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __STDARG_H
#define __STDARG_H
#ifdef __VARARGS_H
#error Can't include both STDARG.H and VARARGS.H
#endif
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
typedef void *va_list;
#define __size(x) ((sizeof(x)+sizeof(int)-1) & ~(sizeof(int)-1))
#ifdef __cplusplus
#define va_start(ap, parmN) (ap = ...)
#else
#define va_start(ap, parmN) ((void)((ap) = (va_list)((char *)(&parmN)+__size(parmN))))
#endif
#define va_arg(ap, type) (*(type *)(((*(char **)&(ap))+=__size(type))-(__size(type))))
#define va_end(ap) ((void)0)
#if !__STDC__
#define _va_ptr (...)
#endif
#endif
-------------------------------------------------------------------------------------
5.stdlib.h
/* stdlib.h
Definitions for common types, variables, and functions.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __STDLIB_H
#define __STDLIB_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#ifndef NULL
#include <_null.h>
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
#ifndef _DIV_T
#define _DIV_T
typedef struct {
int quot;
int rem;
} div_t;
#endif
#ifndef _LDIV_T
#define _LDIV_T
typedef struct {
long quot;
long rem;
} ldiv_t;
#endif
#ifndef _WCHAR_T
#define _WCHAR_T
typedef char wchar_t;
#endif
/* Old typedef
*/
typedef void _Cdecl (* atexit_t)(void);
/* Maximum value returned by "rand" function
*/
#define RAND_MAX 0x7FFFU
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
#define MB_CUR_MAX 1
#ifdef __cplusplus
extern "C" {
#endif
void _Cdecl abort(void);
int _Cdecl __abs__(int);
#ifdef __cplusplus
inline int _Cdecl abs(int __x) { return __abs__(__x); }
#else
int _CType abs(int __x);
# define abs(x) __abs__(x)
#endif
int _Cdecl atexit(void (_Cdecl *__func)(void));
double _Cdecl atof(const char *__s);
int _CType atoi(const char *__s);
long _CType atol(const char *__s);
void * _CType bsearch(const void *__key, const void *__base,
size_t __nelem, size_t __width,
int (_CType *fcmp)(const void *,
const void *));
void * _Cdecl calloc(size_t __nitems, size_t __size);
div_t _Cdecl div(int __numer, int __denom);
void _Cdecl exit(int __status);
void _Cdecl free(void *__block);
char * _CType getenv(const char *__name);
long _Cdecl labs(long __x);
ldiv_t _Cdecl ldiv(long __numer, long __denom);
void * _Cdecl malloc(size_t __size);
int _Cdecl mblen(const char *__s, size_t __n);
size_t _Cdecl mbstowcs(wchar_t *__pwcs, const char *__s,
size_t __n);
int _Cdecl mbtowc(wchar_t *__pwc, const char *__s, size_t __n);
void _CType qsort(void *__base, size_t __nelem, size_t __width,
int _CType (*__fcmp)(const void *, const void *));
int _Cdecl rand(void);
void *_Cdecl realloc(void *__block, size_t __size);
void _Cdecl srand(unsigned __seed);
double _Cdecl strtod(const char *__s, char **__endptr);
long _Cdecl strtol(const char *__s, char **__endptr,
int __radix);
long double _Cdecl _strtold(const char *__s, char **__endptr);
unsigned long _Cdecl strtoul(const char *__s, char **__endptr,
int __radix);
int _Cdecl system(const char *__command);
size_t _Cdecl wcstombs(char *__s, const wchar_t *__pwcs,
size_t __n);
int _Cdecl wctomb(char *__s, wchar_t __wc);
#ifdef __cplusplus
}
#endif
#if !__STDC__
/* Variables */
extern int _Cdecl _doserrno;
extern int _Cdecl errno;
/*
These 2 constants are defined in MS's stdlib.h. Rather than defining them
all the time and invading the ANSI programmers name space we'll only make
them visible when __STDC__ is *off*. Anybody using these constants ain't
writing standard C anyway!
*/
#define DOS_MODE 0
#define OS2_MODE 1
extern unsigned _Cdecl _psp;
extern char **_Cdecl environ;
extern int _Cdecl _fmode;
extern unsigned char _Cdecl _osmajor;
extern unsigned char _Cdecl _osminor;
extern unsigned int _Cdecl _version;
extern char *_Cdecl sys_errlist[];
extern int _Cdecl sys_nerr;
/* Constants for MSC pathname functions */
#define _MAX_PATH 80
#define _MAX_DRIVE 3
#define _MAX_DIR 66
#define _MAX_FNAME 9
#define _MAX_EXT 5
#ifdef __cplusplus
inline int _Cdecl random(int __num)
{ return(int)(((long)rand()*__num)/(RAND_MAX+1)); }
/* need prototype of time() for C++ randomize() */
extern "C" long _Cdecl time(long *);
inline void _Cdecl randomize(void) { srand((unsigned) time(NULL)); }
inline int _Cdecl atoi(const char *__s) { return (int) atol(__s); }
#else
#define random(num)(int)(((long)rand()*(num))/(RAND_MAX+1))
#define randomize() srand((unsigned)time(NULL))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define atoi(s) ((int) atol(s))
#endif
#ifdef __cplusplus
extern "C" {
#endif
long double _Cdecl _atold(const char *__s);
char *_Cdecl ecvt(double __value, int __ndig, int *__dec,
int *__sign);
void _Cdecl _exit(int __status);
char *_Cdecl fcvt(double __value, int __ndig, int *__dec,
int *__sign);
char * _CType _fullpath( char *__buf,
const char *__path,
size_t __maxlen );
char *_Cdecl gcvt(double __value, int __ndec, char *__buf);
char *_CType itoa(int __value, char *__string, int __radix);
void *_Cdecl lfind(const void *__key, const void *__base,
size_t *__num, size_t __width,
int _Cdecl(*__fcmp)(const void *, const void *));
unsigned long _Cdecl _lrotl(unsigned long __val, int __count);
unsigned long _Cdecl _lrotr(unsigned long __val, int __count);
void *_Cdecl lsearch(const void *__key, void *__base,
size_t *__num, size_t __width,
int _Cdecl(*__fcmp)(const void *, const void *));
char * _CType ltoa(long __value, char *__string, int __radix);
void _Cdecl _makepath( char *__path,
const char *__drive,
const char *__dir,
const char *__name,
const char *__ext );
int _Cdecl putenv(const char *__name);
unsigned _Cdecl _rotl(unsigned __value, int __count);
unsigned _Cdecl _rotr(unsigned __value, int __count);
unsigned _Cdecl __rotl__(unsigned __value, int __count); /* intrinsic */
unsigned _Cdecl __rotr__(unsigned __value, int __count); /* intrinsic */
void _Cdecl _searchenv(const char *__file,
const char *__varname,
char *__pathname);
void _Cdecl _splitpath( const char *__path,
char *__drive,
char *__dir,
char *__name,
char *__ext );
void _Cdecl swab(char *__from, char *__to, int __nbytes);
char *_CType ultoa(unsigned long __value, char *__string,
int __radix);
#ifdef __cplusplus
}
#endif
#endif /* !__STDC__ */
#endif /* __STDLIB_H */
-----------------------------------------------------------------------------------
6.ctype.h
/* ctype.h
Defines the ctype macros.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __CTYPE_H
#define __CTYPE_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#define _IS_SP 1 /* is space */
#define _IS_DIG 2 /* is digit indicator */
#define _IS_UPP 4 /* is upper case */
#define _IS_LOW 8 /* is lower case */
#define _IS_HEX 16 /* [0..9] or [A-F] or [a-f] */
#define _IS_CTL 32 /* Control */
#define _IS_PUN 64 /* punctuation */
extern char _Cdecl _ctype[]; /* Character type array */
#ifdef __cplusplus
extern "C" {
#endif
int _Cdecl isalnum (int __c);
int _Cdecl isalpha (int __c);
int _Cdecl isascii (int __c);
int _Cdecl iscntrl (int __c);
int _Cdecl isdigit (int __c);
int _Cdecl isgraph (int __c);
int _Cdecl islower (int __c);
int _Cdecl isprint (int __c);
int _Cdecl ispunct (int __c);
int _Cdecl isspace (int __c);
int _Cdecl isupper (int __c);
int _Cdecl isxdigit(int __c);
#ifdef __cplusplus
}
#endif
#define isalnum(c) (_ctype[(c) + 1] & (_IS_DIG | _IS_UPP | _IS_LOW))
#define isalpha(c) (_ctype[(c) + 1] & (_IS_UPP | _IS_LOW))
#define isascii(c) ((unsigned)(c) < 128)
#define iscntrl(c) (_ctype[(c) + 1] & _IS_CTL)
#define isdigit(c) (_ctype[(c) + 1] & _IS_DIG)
#define isgraph(c) ((c) >= 0x21 && (c) <= 0x7e)
#define islower(c) (_ctype[(c) + 1] & _IS_LOW)
#define isprint(c) ((c) >= 0x20 && (c) <= 0x7e)
#define ispunct(c) (_ctype[(c) + 1] & _IS_PUN)
#define isspace(c) (_ctype[(c) + 1] & _IS_SP)
#define isupper(c) (_ctype[(c) + 1] & _IS_UPP)
#define isxdigit(c) (_ctype[(c) + 1] & (_IS_DIG | _IS_HEX))
#define toascii(c) ((c) & 0x7f)
#if !__STDC__
#define _toupper(c) ((c) + 'A' - 'a')
#define _tolower(c) ((c) + 'a' - 'A')
#endif
#ifdef __cplusplus
extern "C" {
#endif
int _CType tolower(int __ch);
int _CType _ftolower(int __ch);
int _CType toupper(int __ch);
int _CType _ftoupper(int __ch);
#ifdef __cplusplus
}
#endif
#endif
------------------------------------------------------------------------------
7.limits.h
/* limits.h
Defines implementation specific limits on type values.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __LIMITS_H
#define __LIMITS_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#define CHAR_BIT 8
#if ('\x80' < 0)
#define CHAR_MAX 127
#define CHAR_MIN (-128)
#else
#define CHAR_MAX 255
#define CHAR_MIN 0
#endif
#define SCHAR_MAX 127
#define SCHAR_MIN (-128)
#define UCHAR_MAX 255
#define SHRT_MAX 0x7FFF
#define SHRT_MIN ((int)0x8000)
#define USHRT_MAX 0xFFFFU
#define INT_MAX 0x7FFF
#define INT_MIN ((int)0x8000)
#define UINT_MAX 0xFFFFU
#define LONG_MAX 0x7FFFFFFFL
#define LONG_MIN ((long)0x80000000L)
#define ULONG_MAX 0xFFFFFFFFUL
#define MB_LEN_MAX 1
#endif
-------------------------------------------------------------
8.setjmp.h
/* setjmp.h
Defines typedef and functions for setjmp/longjmp.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __SETJMP_H
#define __SETJMP_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
typedef struct __jmp_buf {
unsigned j_sp;
unsigned j_ss;
unsigned j_flag;
unsigned j_cs;
unsigned j_ip;
unsigned j_bp;
unsigned j_di;
unsigned j_es;
unsigned j_si;
unsigned j_ds;
} jmp_buf[1];
#ifdef __cplusplus
extern "C" {
#endif
void _CType longjmp(jmp_buf __jmpb, int __retval);
int _CType setjmp(jmp_buf __jmpb);
#ifdef __cplusplus
}
#endif
#endif
-----------------------------------------------------------------------------
9.stddef.h
/* stddef.h
Definitions for common types, and NULL
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __STDDEF_H
#define __STDDEF_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#ifndef NULL
#include <_null.h>
#endif
#ifndef _PTRDIFF_T
#define _PTRDIFF_T
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
typedef long ptrdiff_t;
#else
typedef int ptrdiff_t;
#endif
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
#define offsetof( s_name, m_name ) (size_t)&(((s_name *)0)->m_name)
#ifndef _WCHAR_T
#define _WCHAR_T
typedef char wchar_t;
#endif
#endif /* __STDDEF_H */
10.string.h
/* string.h
Definitions for memory and string functions.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __STRING_H
#define __STRING_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#ifndef NULL
#include <_null.h>
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
#ifdef __cplusplus
extern "C" {
#endif
void * _Cdecl memchr (const void *__s, int __c, size_t __n);
int _Cdecl memcmp(const void *__s1,
const void *__s2, size_t __n);
void * _Cdecl memcpy(void *__dest, const void *__src,
size_t __n);
void * _CType memmove(void *__dest, const void *__src,
size_t __n);
void * _CType memset(void *__s, int __c, size_t __n);
char * _CType strcat(char *__dest, const char *__src);
char * _CType strchr(const char *__s, int __c);
int _CType strcmp(const char *__s1, const char *__s2);
int _Cdecl strcoll(const char *__s1, const char *__s2);
char * _CType strcpy(char *__dest, const char *__src);
size_t _Cdecl strcspn(const char *__s1, const char *__s2);
char * _Cdecl strerror(int __errnum);
size_t _CType strlen(const char *__s);
char * _CType strncat(char *__dest, const char *__src,
size_t __maxlen);
int _CType strncmp(const char *__s1, const char *__s2,
size_t __maxlen);
char * _CType strncpy(char *__dest, const char *__src,
size_t __maxlen);
char * _CType strpbrk(const char *__s1, const char *__s2);
char * _CType strrchr(const char *__s, int __c);
size_t _Cdecl strspn(const char *__s1, const char *__s2);
char * _Cdecl strstr(const char *__s1, const char *__s2);
char * _CType strtok(char *__s1, const char *__s2);
size_t _Cdecl strxfrm(char *__s1, const char *__s2,
size_t __n );
char * _Cdecl _strerror(const char *__s);
#if !__STDC__
/* compatibility with other compilers */
#define strcmpi(s1,s2) stricmp(s1,s2)
#define strncmpi(s1,s2,n) strnicmp(s1,s2,n)
void * _Cdecl memccpy(void *__dest, const void *__src,
int __c, size_t __n);
int _Cdecl memicmp(const void *__s1, const void *__s2,
size_t __n);
void _Cdecl movedata(unsigned __srcseg,unsigned __srcoff,
unsigned __dstseg,unsigned __dstoff, size_t __n);
char * _CType stpcpy(char *__dest, const char *__src);
char * _Cdecl _stpcpy(char *__dest, const char *__src);
char * _Cdecl strdup(const char *__s);
int _CType stricmp(const char *__s1, const char *__s2);
char * _CType strlwr(char *__s);
int _CType strnicmp(const char *__s1, const char *__s2,
size_t __maxlen);
char * _Cdecl strnset(char *__s, int __ch, size_t __n);
char * _Cdecl strrev(char *__s);
char * _Cdecl strset(char *__s, int __ch);
char * _CType strupr(char *__s);
void far * far cdecl _fmemccpy(void far *__dest, const void far *__src,
int c, size_t __n);
void far * far cdecl _fmemchr(const void far *__s, int c, size_t __n);
int far cdecl _fmemcmp(const void far *__s1, const void far *__s2,
size_t __n);
void far * far cdecl _fmemcpy(void far *__dest, const void far *__src,
size_t __n);
int far cdecl _fmemicmp(const void far *__s1, const void far *__s2,
size_t __n);
void far * far cdecl _fmemmove(void far *__dest, const void far *__src,
size_t __n);
void far * far cdecl _fmemset(void far *__s, int c, size_t __n);
void far cdecl _fmovmem(const void far *__src, void far *__dest,
unsigned __length);
void far cdecl _fsetmem(void far *__dest,unsigned __length,
char __value);
char far * far cdecl _fstrcat(char far *__dest, const char far *__src);
char far * far cdecl _fstrchr(const char far *__s, int c);
int far cdecl _fstrcmp(const char far *__s1, const char far *__s2);
char far * far cdecl _fstrcpy(char far *__dest, const char far *__src);
size_t far cdecl _fstrcspn(const char far *__s1, const char far *__s2);
char far * far cdecl _fstrdup(const char far *__s);
int far cdecl _fstricmp(const char far *__s1, const char far *__s2);
size_t far cdecl _fstrlen(const char far *__s);
char far * far cdecl _fstrlwr(char far *__s);
char far * far cdecl _fstrncat(char far *__dest, const char far *__src,
size_t maxlen);
int far cdecl _fstrncmp(const char far *__s1, const char far *__s2,
size_t maxlen);
char far * far cdecl _fstrncpy(char far *__dest, const char far *__src,
size_t maxlen);
int far cdecl _fstrnicmp(const char far *__s1, const char far *__s2,
size_t maxlen);
char far * far cdecl _fstrnset(char far *__s, int ch, size_t __n);
char far * far cdecl _fstrpbrk(const char far *__s1, const char far *__s2);
char far * far cdecl _fstrrchr(const char far *__s, int c);
char far * far cdecl _fstrrev(char far *__s);
char far * far cdecl _fstrset(char far *__s, int ch);
size_t far cdecl _fstrspn(const char far *__s1, const char far *__s2);
char far * far cdecl _fstrstr(const char far *__s1, const char far *__s2);
char far * far cdecl _fstrtok(char far *__s1, const char far *__s2);
char far * far cdecl _fstrupr(char far *__s);
#endif /* ! __STDC__ */
#ifdef __cplusplus
}
#endif
#endif
11.errno.h
/* errno.h
Defines the system error variable errno and the error
numbers set by system calls. Errors which exist in Unix(tm)
but not MSDOS have value -1.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __ERRNO_H
#define __ERRNO_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
/* Dos Error Codes */
#define EZERO 0 /* Error 0 */
#define EINVFNC 1 /* Invalid function number */
#define ENOFILE 2 /* File not found */
#define ENOPATH 3 /* Path not found */
#define ECONTR 7 /* Memory blocks destroyed */
#define EINVMEM 9 /* Invalid memory block address */
#define EINVENV 10 /* Invalid environment */
#define EINVFMT 11 /* Invalid format */
#define EINVACC 12 /* Invalid access code */
#define EINVDAT 13 /* Invalid data */
#define EINVDRV 15 /* Invalid drive specified */
#define ECURDIR 16 /* Attempt to remove CurDir */
#define ENOTSAM 17 /* Not same device */
#define ENMFILE 18 /* No more files */
#define ENOENT 2 /* No such file or directory*/
#define EMFILE 4 /* Too many open files */
#define EACCES 5 /* Permission denied */
#define EBADF 6 /* Bad file number */
#define ENOMEM 8 /* Not enough core */
#define ENODEV 15 /* No such device */
#define EINVAL 19 /* Invalid argument */
#define E2BIG 20 /* Arg list too long */
#define ENOEXEC 21 /* Exec format error */
#define EXDEV 22 /* Cross-device link */
#define EDOM 33 /* Math argument */
#define ERANGE 34 /* Result too large */
#define EEXIST 35 /* File already exists */
#define EDEADLOCK 36 /* Locking violation */
#define ECHILD -1 /* Unix/DOS */
#define EFAULT -1 /* Unknown error */
#define EPERM -1 /* UNIX - not MSDOS */
#define ESRCH -1 /* UNIX - not MSDOS */
#define EINTR -1 /* UNIX - not MSDOS */
#define EIO -1 /* UNIX - not MSDOS */
#define ENXIO -1 /* UNIX - not MSDOS */
#define EAGAIN -1 /* UNIX - not MSDOS */
#define ENOTBLK -1 /* UNIX - not MSDOS */
#define EBUSY -1 /* UNIX - not MSDOS */
#define ENOTDIR -1 /* UNIX - not MSDOS */
#define EISDIR -1 /* UNIX - not MSDOS */
#define ENFILE -1 /* UNIX - not MSDOS */
#define ENOTTY -1 /* UNIX - not MSDOS */
#define ETXTBSY -1 /* UNIX - not MSDOS */
#define EFBIG -1 /* UNIX - not MSDOS */
#define ENOSPC -1 /* UNIX - not MSDOS */
#define ESPIPE -1 /* UNIX - not MSDOS */
#define EROFS -1 /* UNIX - not MSDOS */
#define EMLINK -1 /* UNIX - not MSDOS */
#define EPIPE -1 /* UNIX - not MSDOS */
#define EUCLEAN -1 /* UNIX - not MSDOS */
extern int _Cdecl errno;
extern int _Cdecl _doserrno;
#if !__STDC__
#define _sys_nerr 35 /* highest defined system error number */
#endif
#endif
12.locale.h
/* locale.h
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __LOCALE_H
#define __LOCALE_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#ifndef NULL
#include <_null.h>
#endif
#define LC_ALL 0
#define LC_COLLATE 1
#define LC_CTYPE 2
#define LC_MONETARY 3
#define LC_NUMERIC 4
#define LC_TIME 5
struct lconv
{
char *decimal_point;
char *thousands_sep;
char *grouping;
char *int_curr_symbol;
char *currency_symbol;
char *mon_decimal_point;
char *mon_thousands_sep;
char *mon_grouping;
char *positive_sign;
char *negative_sign;
char int_frac_digits;
char frac_digits;
char p_cs_precedes;
char p_sep_by_space;
char n_cs_precedes;
char n_sep_by_space;
char p_sign_posn;
char n_sign_posn;
};
#ifdef __cplusplus
extern "C" {
#endif
char * _Cdecl setlocale( int __category, const char *__locale );
struct lconv * _Cdecl localeconv( void );
#ifdef __cplusplus
}
#endif
#endif
13.signal.h
/* signal.h
Definitions for ANSI defined signaling capability
Copyright (c) 1988, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __SIGNAL_H
#define __SIGNAL_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
typedef int sig_atomic_t; /* Atomic entity type (ANSI) */
typedef void _Cdecl (* _CatcherPTR)();
#define SIG_DFL ((_CatcherPTR)0) /* Default action */
#define SIG_IGN ((_CatcherPTR)1) /* Ignore action */
#define SIG_ERR ((_CatcherPTR)-1) /* Error return */
#define SIGABRT 22
#define SIGFPE 8 /* Floating point trap */
#define SIGILL 4 /* Illegal instruction */
#define SIGINT 2
#define SIGSEGV 11 /* Memory access violation */
#define SIGTERM 15
#ifdef __cplusplus
extern "C" {
#endif
int _Cdecl raise(int __sig);
#ifdef __cplusplus
void _Cdecl (* _Cdecl signal(int __sig, void _Cdecl (* __func)(int))) (int);
}
#else
void _Cdecl (* _Cdecl signal(int __sig, void _Cdecl (* func)())) (int);
#endif
#endif
14.stdio.h
/* stdio.h
Definitions for stream input/output.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __STDIO_H
#define __STDIO_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#ifndef NULL
#include <_null.h>
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
/* Definition of the file position type
*/
typedef long fpos_t;
/* Definition of the control structure for streams
*/
typedef struct {
int level; /* fill/empty level of buffer */
unsigned flags; /* File status flags */
char fd; /* File descriptor */
unsigned char hold; /* Ungetc char if no buffer */
int bsize; /* Buffer size */
unsigned char *buffer; /* Data transfer buffer */
unsigned char *curp; /* Current active pointer */
unsigned istemp; /* Temporary file indicator */
short token; /* Used for validity checking */
} FILE; /* This is the FILE object */
/* Bufferisation type to be used as 3rd argument for "setvbuf" function
*/
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2
/* "flags" bits definitions
*/
#define _F_RDWR 0x0003 /* Read/write flag */
#define _F_READ 0x0001 /* Read only file */
#define _F_WRIT 0x0002 /* Write only file */
#define _F_BUF 0x0004 /* Malloc'ed Buffer data */
#define _F_LBUF 0x0008 /* line-buffered file */
#define _F_ERR 0x0010 /* Error indicator */
#define _F_EOF 0x0020 /* EOF indicator */
#define _F_BIN 0x0040 /* Binary file indicator */
#define _F_IN 0x0080 /* Data is incoming */
#define _F_OUT 0x0100 /* Data is outgoing */
#define _F_TERM 0x0200 /* File is a terminal */
/* End-of-file constant definition
*/
#define EOF (-1) /* End of file indicator */
/* Number of files that can be open simultaneously
*/
#if __STDC__
#define FOPEN_MAX 18 /* Able to have 18 files (20 - stdaux & stdprn) */
#else
#define FOPEN_MAX 20 /* Able to have 20 files */
#define SYS_OPEN 20
#endif
#define FILENAME_MAX 80
/* Default buffer size use by "setbuf" function
*/
#define BUFSIZ 512 /* Buffer size for stdio */
/* Size of an arry large enough to hold a temporary file name string
*/
#define L_ctermid 5 /* CON: plus null byte */
#define P_tmpdir "" /* temporary directory */
#define L_tmpnam 13 /* tmpnam buffer size */
/* Constants to be used as 3rd argument for "fseek" function
*/
#define SEEK_CUR 1
#define SEEK_END 2
#define SEEK_SET 0
/* Number of unique file names that shall be generated by "tmpnam" function
*/
#define TMP_MAX 0xFFFF
/* Standard I/O predefined streams
*/
#if !defined( _RTLDLL )
extern FILE _Cdecl _streams[];
extern unsigned _Cdecl _nfile;
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
#if !__STDC__
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
#endif
#else
#ifdef __cplusplus
extern "C" {
#endif
FILE far * far __getStream(int);
#ifdef __cplusplus
}
#endif
#define stdin __getStream(0)
#define stdout __getStream(1)
#define stderr __getStream(2)
#define stdaux __getStream(3)
#define stdprn __getStream(4)
#endif
#ifdef __cplusplus
extern "C" {
#endif
void _Cdecl clearerr(FILE *__stream);
int _Cdecl fclose(FILE *__stream);
int _Cdecl fflush(FILE *__stream);
int _Cdecl fgetc(FILE *__stream);
int _Cdecl fgetpos(FILE *__stream, fpos_t *__pos);
char *_Cdecl fgets(char *__s, int __n, FILE *__stream);
FILE *_Cdecl fopen(const char *__path, const char *__mode);
int _Cdecl fprintf(FILE *__stream, const char *__format, ...);
int _Cdecl fputc(int __c, FILE *__stream);
int _Cdecl fputs(const char *__s, FILE *__stream);
size_t _Cdecl fread(void *__ptr, size_t __size, size_t __n,
FILE *__stream);
FILE *_Cdecl freopen(const char *__path, const char *__mode,
FILE *__stream);
int _Cdecl fscanf(FILE *__stream, const char *__format, ...);
int _Cdecl fseek(FILE *__stream, long __offset, int __whence);
int _Cdecl fsetpos(FILE *__stream, const fpos_t *__pos);
long _Cdecl ftell(FILE *__stream);
size_t _Cdecl fwrite(const void *__ptr, size_t __size, size_t __n,
FILE *__stream);
char *_Cdecl gets(char *__s);
void _Cdecl perror(const char *__s);
int _Cdecl printf(const char *__format, ...);
int _Cdecl puts(const char *__s);
int _CType remove(const char *__path);
int _CType rename(const char *__oldname,const char *__newname);
void _Cdecl rewind(FILE *__stream);
int _Cdecl scanf(const char *__format, ...);
void _Cdecl setbuf(FILE *__stream, char *__buf);
int _Cdecl setvbuf(FILE *__stream, char *__buf,
int __type, size_t __size);
int _Cdecl sprintf(char *__buffer, const char *__format, ...);
int _Cdecl sscanf(const char *__buffer,
const char *__format, ...);
char *_Cdecl strerror(int __errnum);
FILE *_Cdecl tmpfile(void);
char *_Cdecl tmpnam(char *__s);
int _Cdecl ungetc(int __c, FILE *__stream);
int _Cdecl vfprintf(FILE *__stream, const char *__format,
void *__arglist);
int _Cdecl vfscanf(FILE *__stream, const char *__format,
void *__arglist);
int _CType vprintf(const char *__format, void *__arglist);
int _Cdecl vscanf(const char *__format, void *__arglist);
int _Cdecl vsprintf(char *__buffer, const char *__format,
void *__arglist);
int _Cdecl vsscanf(const char *__buffer, const char *__format,
void *__arglist);
int _CType unlink(const char *__path);
int _Cdecl getc(FILE *__fp);
int _Cdecl getchar(void);
int _Cdecl putchar(const int __c);
int _Cdecl putc(const int __c, FILE *__fp);
int _Cdecl feof(FILE *__fp);
int _Cdecl ferror(FILE *__fp);
#if !__STDC__
int _Cdecl fcloseall(void);
FILE *_Cdecl fdopen(int __handle, char *__type);
int _Cdecl fgetchar(void);
int _Cdecl flushall(void);
int _Cdecl fputchar(int __c);
FILE * _Cdecl _fsopen (const char *__path, const char *__mode,
int __shflag);
int _Cdecl getw(FILE *__stream);
int _Cdecl putw(int __w, FILE *__stream);
int _Cdecl rmtmp(void);
char * _Cdecl _strerror(const char *__s);
char * _Cdecl tempnam(char *__dir, char *__pfx);
#define fileno(f) ((f)->fd)
#endif
int _Cdecl _fgetc(FILE *__stream); /* used by getc() macro */
int _Cdecl _fputc(char __c, FILE *__stream); /* used by putc() macro */
#ifdef __cplusplus
}
#endif
/* The following macros provide for common functions */
#define ferror(f) ((f)->flags & _F_ERR)
#define feof(f) ((f)->flags & _F_EOF)
#define getc(f) \
((--((f)->level) >= 0) ? (unsigned char)(*(f)->curp++) : \
_fgetc (f))
#define putc(c,f) \
((++((f)->level) < 0) ? (unsigned char)(*(f)->curp++=(c)) : \
_fputc ((c),f))
#define getchar() getc(stdin)
#define putchar(c) putc((c), stdout)
#define ungetc(c,f) ungetc((c),f) /* traditionally a macro */
#endif
15.time.h
/* time.h
Struct and function declarations for dealing with time.
Copyright (c) 1987, 1991 by Borland International
All Rights Reserved.
*/
#ifndef __TIME_H
#define __TIME_H
#if !defined( __DEFS_H )
#include <_defs.h>
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
#ifndef _TIME_T
#define _TIME_T
typedef long time_t;
#endif
#ifndef _CLOCK_T
#define _CLOCK_T
typedef long clock_t;
#define CLOCKS_PER_SEC 18.2
#define CLK_TCK 18.2
#endif /* _TIME_T */
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
#ifdef __cplusplus
extern "C" {
#endif
char * _Cdecl asctime(const struct tm *__tblock);
char * _Cdecl ctime(const time_t *__time);
double _Cdecl difftime(time_t __time2, time_t __time1);
struct tm * _Cdecl gmtime(const time_t *__timer);
struct tm * _Cdecl localtime(const time_t *__timer);
time_t _Cdecl time(time_t *__timer);
time_t _Cdecl mktime(struct tm *__timeptr);
clock_t _Cdecl clock(void);
size_t _Cdecl strftime(char *__s, size_t __maxsize,
const char *__fmt, const struct tm *__t);
#if !__STDC__
extern int _Cdecl daylight;
extern long _Cdecl timezone;
extern char * const _Cdecl tzname[2];
int _Cdecl stime(time_t *__tp);
void _Cdecl tzset(void);
char * _Cdecl _strdate(char *datestr);
char * _Cdecl _strtime(char *timestr);
#endif
#ifdef __cplusplus
}
#endif
#endif
另外 C95(C89修正案1) 增加了3个头文件
1
iso646.h
/* Copyright (C) 1997, 1999 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GCC 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* As a special exception, if you include this header file into source
files compiled by GCC, this header file does not by itself cause
the resulting executable to be covered by the GNU General Public
License. This exception does not however invalidate any other
reasons why the executable file might be covered by the GNU General
Public License. */
/*
* ISO C Standard: 7.9 Alternative spellings <iso646.h>
*/
#ifndef _ISO646_H
#define _ISO646_H
#ifndef __cplusplus
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=
#endif
#endif
2 . wchar.h
/*
* wchar.h
* This file has no copyright assigned and is placed in the Public Domain.
* This file is a part of the mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER within the package.
*
* Defines of all functions for supporting wide characters. Actually it
* just includes all those headers, which is not a good thing to do from a
* processing time point of view, but it does mean that everything will be
* in sync.
*
*/
#ifndef _WCHAR_H_
#define _WCHAR_H_
/* All the headers include this file. */
#include <_mingw.h>
#ifndef RC_INVOKED
#define __need_size_t
#define __need_wint_t
#define __need_wchar_t
#define __need_NULL
#include <stddef.h>
#ifndef __VALIST
#if defined __GNUC__ && __GNUC__ >= 3
#define __need___va_list
#include <stdarg.h>
#define __VALIST __builtin_va_list
#else
#define __VALIST char*
#endif
#endif
#endif /* Not RC_INVOKED */
/*
* MSDN says that isw* char classifications are in wchar.h and wctype.h.
* Although the wctype names are ANSI, their exposure in this header is
* not.
*/
#include <wctype.h>
#ifndef __STRICT_ANSI__
/* This is necessary to support the the non-ANSI wchar declarations
here. */
#include <sys/types.h>
#endif /* __STRICT_ANSI__ */
#define WCHAR_MIN 0
#define WCHAR_MAX ((wchar_t)-1)
#ifndef WEOF
#define WEOF (wchar_t)(0xFFFF)
#endif
#ifndef RC_INVOKED
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _FILE_DEFINED /* Also in stdio.h */
#define _FILE_DEFINED
typedef struct _iobuf
{
char* _ptr;
int _cnt;
char* _base;
int _flag;
int _file;
int _charbuf;
int _bufsiz;
char* _tmpfname;
} FILE;
#endif /* Not _FILE_DEFINED */
#ifndef _TIME_T_DEFINED /* Also in time.h */
typedef long time_t;
#define _TIME_T_DEFINED
#endif
#ifndef _TM_DEFINED /* Also in time.h */
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
#define _TM_DEFINED
#endif
#ifndef _WSTDIO_DEFINED
/* Also in stdio.h - keep in sync */
_CRTIMP int __cdecl fwprintf (FILE*, const wchar_t*, ...);
_CRTIMP int __cdecl wprintf (const wchar_t*, ...);
_CRTIMP int __cdecl swprintf (wchar_t*, const wchar_t*, ...);
_CRTIMP int __cdecl _snwprintf (wchar_t*, size_t, const wchar_t*, ...);
_CRTIMP int __cdecl vfwprintf (FILE*, const wchar_t*, __VALIST);
_CRTIMP int __cdecl vwprintf (const wchar_t*, __VALIST);
_CRTIMP int __cdecl vswprintf (wchar_t*, const wchar_t*, __VALIST);
_CRTIMP int __cdecl _vsnwprintf (wchar_t*, size_t, const wchar_t*, __VALIST);
_CRTIMP int __cdecl fwscanf (FILE*, const wchar_t*, ...);
_CRTIMP int __cdecl wscanf (const wchar_t*, ...);
_CRTIMP int __cdecl swscanf (const wchar_t*, const wchar_t*, ...);
_CRTIMP wint_t __cdecl fgetwc (FILE*);
_CRTIMP wint_t __cdecl fputwc (wchar_t, FILE*);
_CRTIMP wint_t __cdecl ungetwc (wchar_t, FILE*);
#ifdef __MSVCRT__
_CRTIMP wchar_t* __cdecl fgetws (wchar_t*, int, FILE*);
_CRTIMP int __cdecl fputws (const wchar_t*, FILE*);
_CRTIMP wint_t __cdecl getwc (FILE*);
_CRTIMP wint_t __cdecl getwchar (void);
_CRTIMP wint_t __cdecl putwc (wint_t, FILE*);
_CRTIMP wint_t __cdecl putwchar (wint_t);
#ifndef __STRICT_ANSI__
_CRTIMP wchar_t* __cdecl _getws (wchar_t*);
_CRTIMP int __cdecl _putws (const wchar_t*);
_CRTIMP FILE* __cdecl _wfdopen(int, wchar_t *);
_CRTIMP FILE* __cdecl _wfopen (const wchar_t*, const wchar_t*);
_CRTIMP FILE* __cdecl _wfreopen (const wchar_t*, const wchar_t*, FILE*);
_CRTIMP FILE* __cdecl _wfsopen (const wchar_t*, const wchar_t*, int);
_CRTIMP wchar_t* __cdecl _wtmpnam (wchar_t*);
_CRTIMP wchar_t* __cdecl _wtempnam (const wchar_t*, const wchar_t*);
_CRTIMP int __cdecl _wrename (const wchar_t*, const wchar_t*);
_CRTIMP int __cdecl _wremove (const wchar_t*);
_CRTIMP void __cdecl _wperror (const wchar_t*);
_CRTIMP FILE* __cdecl _wpopen (const wchar_t*, const wchar_t*);
#endif /* __STRICT_ANSI__ */
#endif /* __MSVCRT__ */
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
int __cdecl snwprintf (wchar_t* s, size_t n, const wchar_t* format, ...);
__CRT_INLINE int __cdecl
vsnwprintf (wchar_t* s, size_t n, const wchar_t* format, __VALIST arg)
{ return _vsnwprintf ( s, n, format, arg);}
int __cdecl vwscanf (const wchar_t * __restrict__, __VALIST);
int __cdecl vfwscanf (FILE * __restrict__,
const wchar_t * __restrict__, __VALIST);
int __cdecl vswscanf (const wchar_t * __restrict__,
const wchar_t * __restrict__, __VALIST);
#endif
#define _WSTDIO_DEFINED
#endif /* _WSTDIO_DEFINED */
#ifndef _WSTDLIB_DEFINED /* also declared in stdlib.h */
_CRTIMP long __cdecl wcstol (const wchar_t*, wchar_t**, int);
_CRTIMP unsigned long __cdecl wcstoul (const wchar_t*, wchar_t**, int);
_CRTIMP double __cdecl wcstod (const wchar_t*, wchar_t**);
#if !defined __NO_ISOCEXT /* extern stub in static libmingwex.a */
__CRT_INLINE float __cdecl wcstof( const wchar_t *nptr, wchar_t **endptr)
{ return (wcstod(nptr, endptr)); }
long double __cdecl wcstold (const wchar_t * __restrict__, wchar_t ** __restrict__);
#endif /* __NO_ISOCEXT */
#define _WSTDLIB_DEFINED
#endif /* _WSTDLIB_DEFINED */
#ifndef _WTIME_DEFINED
#ifndef __STRICT_ANSI__
#ifdef __MSVCRT__
/* wide function prototypes, also declared in time.h */
_CRTIMP wchar_t* __cdecl _wasctime (const struct tm*);
_CRTIMP wchar_t* __cdecl _wctime (const time_t*);
_CRTIMP wchar_t* __cdecl _wstrdate (wchar_t*);
_CRTIMP wchar_t* __cdecl _wstrtime (wchar_t*);
#if __MSVCRT_VERSION__ >= 0x601
_CRTIMP wchar_t* __cdecl _wctime64 (const __time64_t*);
#endif
#endif /* __MSVCRT__ */
#endif /* __STRICT_ANSI__ */
_CRTIMP size_t __cdecl wcsftime (wchar_t*, size_t, const wchar_t*, const struct tm*);
#define _WTIME_DEFINED
#endif /* _WTIME_DEFINED */
#ifndef _WSTRING_DEFINED
/*
* Unicode versions of the standard string calls.
* Also in string.h.
*/
_CRTIMP wchar_t* __cdecl wcscat (wchar_t*, const wchar_t*);
_CRTIMP wchar_t* __cdecl wcschr (const wchar_t*, wchar_t);
_CRTIMP int __cdecl wcscmp (const wchar_t*, const wchar_t*);
_CRTIMP int __cdecl wcscoll (const wchar_t*, const wchar_t*);
_CRTIMP wchar_t* __cdecl wcscpy (wchar_t*, const wchar_t*);
_CRTIMP size_t __cdecl wcscspn (const wchar_t*, const wchar_t*);
/* Note: _wcserror requires __MSVCRT_VERSION__ >= 0x0700. */
_CRTIMP size_t __cdecl wcslen (const wchar_t*);
_CRTIMP wchar_t* __cdecl wcsncat (wchar_t*, const wchar_t*, size_t);
_CRTIMP int __cdecl wcsncmp(const wchar_t*, const wchar_t*, size_t);
_CRTIMP wchar_t* __cdecl wcsncpy(wchar_t*, const wchar_t*, size_t);
_CRTIMP wchar_t* __cdecl wcspbrk(const wchar_t*, const wchar_t*);
_CRTIMP wchar_t* __cdecl wcsrchr(const wchar_t*, wchar_t);
_CRTIMP size_t __cdecl wcsspn(const wchar_t*, const wchar_t*);
_CRTIMP wchar_t* __cdecl wcsstr(const wchar_t*, const wchar_t*);
_CRTIMP wchar_t* __cdecl wcstok(wchar_t*, const wchar_t*);
_CRTIMP size_t __cdecl wcsxfrm(wchar_t*, const wchar_t*, size_t);
#ifndef __STRICT_ANSI__
/*
* Unicode versions of non-ANSI functions provided by CRTDLL.
*/
/* NOTE: _wcscmpi not provided by CRTDLL, this define is for portability */
#define _wcscmpi _wcsicmp
_CRTIMP wchar_t* __cdecl _wcsdup (const wchar_t*);
_CRTIMP int __cdecl _wcsicmp (const wchar_t*, const wchar_t*);
_CRTIMP int __cdecl _wcsicoll (const wchar_t*, const wchar_t*);
_CRTIMP wchar_t* __cdecl _wcslwr (wchar_t*);
_CRTIMP int __cdecl _wcsnicmp (const wchar_t*, const wchar_t*, size_t);
_CRTIMP wchar_t* __cdecl _wcsnset (wchar_t*, wchar_t, size_t);
_CRTIMP wchar_t* __cdecl _wcsrev (wchar_t*);
_CRTIMP wchar_t* __cdecl _wcsset (wchar_t*, wchar_t);
_CRTIMP wchar_t* __cdecl _wcsupr (wchar_t*);
#ifdef __MSVCRT__
_CRTIMP int __cdecl _wcsncoll(const wchar_t*, const wchar_t*, size_t);
_CRTIMP int __cdecl _wcsnicoll(const wchar_t*, const wchar_t*, size_t);
#if __MSVCRT_VERSION__ >= 0x0700
_CRTIMP wchar_t* __cdecl _wcserror(int);
_CRTIMP wchar_t* __cdecl __wcserror(const wchar_t*);
#endif
#endif
#ifndef _NO_OLDNAMES
/* NOTE: There is no _wcscmpi, but this is for compatibility. */
__CRT_INLINE int __cdecl
wcscmpi (const wchar_t * __ws1, const wchar_t * __ws2)
{return _wcsicmp (__ws1, __ws2);}
_CRTIMP wchar_t* __cdecl wcsdup (const wchar_t*);
_CRTIMP int __cdecl wcsicmp (const wchar_t*, const wchar_t*);
_CRTIMP int __cdecl wcsicoll (const wchar_t*, const wchar_t*);
_CRTIMP wchar_t* __cdecl wcslwr (wchar_t*);
_CRTIMP int __cdecl wcsnicmp (const wchar_t*, const wchar_t*, size_t);
_CRTIMP wchar_t* __cdecl wcsnset (wchar_t*, wchar_t, size_t);
_CRTIMP wchar_t* __cdecl wcsrev (wchar_t*);
_CRTIMP wchar_t* __cdecl wcsset (wchar_t*, wchar_t);
_CRTIMP wchar_t* __cdecl wcsupr (wchar_t*);
#endif /* Not _NO_OLDNAMES */
#endif /* Not strict ANSI */
#define _WSTRING_DEFINED
#endif /* _WSTRING_DEFINED */
/* These are resolved by -lmsvcp60 */
/* If you don't have msvcp60.dll in your windows system directory, you can
easily obtain it with a search from your favorite search engine. */
#ifndef __STRICT_ANSI__
typedef wchar_t _Wint_t;
#endif
typedef int mbstate_t;
wint_t __cdecl btowc(int);
size_t __cdecl mbrlen(const char *, size_t, mbstate_t *);
size_t __cdecl mbrtowc(wchar_t *, const char *, size_t, mbstate_t *);
size_t __cdecl mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *);
size_t __cdecl wcrtomb(char *, wchar_t, mbstate_t *);
size_t __cdecl wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *);
int __cdecl wctob(wint_t);
#ifndef __NO_ISOCEXT /* these need static lib libmingwex.a */
__CRT_INLINE int __cdecl fwide(FILE* __UNUSED_PARAM(stream), int __UNUSED_PARAM(mode))
{return -1;} /* limited to byte orientation */
__CRT_INLINE int __cdecl mbsinit(const mbstate_t* __UNUSED_PARAM(ps))
{return 1;}
wchar_t* __cdecl wmemset(wchar_t* s, wchar_t c, size_t n);
wchar_t* __cdecl wmemchr(const wchar_t* s, wchar_t c, size_t n);
int wmemcmp(const wchar_t* s1, const wchar_t * s2, size_t n);
wchar_t* __cdecl wmemcpy(wchar_t* __restrict__ s1, const wchar_t* __restrict__ s2,
size_t n);
wchar_t* __cdecl wmemmove(wchar_t* s1, const wchar_t* s2, size_t n);
long long __cdecl wcstoll(const wchar_t* __restrict__ nptr,
wchar_t** __restrict__ endptr, int base);
unsigned long long __cdecl wcstoull(const wchar_t* __restrict__ nptr,
wchar_t ** __restrict__ endptr, int base);
#endif /* __NO_ISOCEXT */
#ifndef __STRICT_ANSI__
/* non-ANSI wide char functions from io.h, direct.h, sys/stat.h and locale.h. */
#ifndef _FSIZE_T_DEFINED
typedef unsigned long _fsize_t;
#define _FSIZE_T_DEFINED
#endif
#ifndef _WFINDDATA_T_DEFINED
struct _wfinddata_t {
unsigned attrib;
time_t time_create; /* -1 for FAT file systems */
time_t time_access; /* -1 for FAT file systems */
time_t time_write;
_fsize_t size;
wchar_t name[260]; /* may include spaces. */
};
struct _wfinddatai64_t {
unsigned attrib;
time_t time_create;
time_t time_access;
time_t time_write;
__int64 size;
wchar_t name[260];
};
struct __wfinddata64_t {
unsigned attrib;
__time64_t time_create;
__time64_t time_access;
__time64_t time_write;
_fsize_t size;
wchar_t name[260];
};
#define _WFINDDATA_T_DEFINED
#endif
/* Wide character versions. Also defined in io.h. */
/* CHECK: I believe these only exist in MSVCRT, and not in CRTDLL. Also
applies to other wide character versions? */
#if !defined (_WIO_DEFINED)
#if defined (__MSVCRT__)
#include <stdint.h> /* For intptr_t. */
_CRTIMP int __cdecl _waccess (const wchar_t*, int);
_CRTIMP int __cdecl _wchmod (const wchar_t*, int);
_CRTIMP int __cdecl _wcreat (const wchar_t*, int);
_CRTIMP long __cdecl _wfindfirst (const wchar_t*, struct _wfinddata_t *);
_CRTIMP int __cdecl _wfindnext (long, struct _wfinddata_t *);
_CRTIMP int __cdecl _wunlink (const wchar_t*);
_CRTIMP int __cdecl _wopen (const wchar_t*, int, ...);
_CRTIMP int __cdecl _wsopen (const wchar_t*, int, int, ...);
_CRTIMP wchar_t* __cdecl _wmktemp (wchar_t*);
_CRTIMP long __cdecl _wfindfirsti64 (const wchar_t*, struct _wfinddatai64_t*);
_CRTIMP int __cdecl _wfindnexti64 (long, struct _wfinddatai64_t*);
#if __MSVCRT_VERSION__ >= 0x0601
_CRTIMP intptr_t __cdecl _wfindfirst64(const wchar_t*, struct __wfinddata64_t*);
_CRTIMP intptr_t __cdecl _wfindnext64(intptr_t, struct __wfinddata64_t*);
#endif /* __MSVCRT_VERSION__ >= 0x0601 */
#endif /* defined (__MSVCRT__) */
#define _WIO_DEFINED
#endif /* _WIO_DEFINED */
#ifndef _WDIRECT_DEFINED
/* Also in direct.h */
#ifdef __MSVCRT__
_CRTIMP int __cdecl _wchdir (const wchar_t*);
_CRTIMP wchar_t* __cdecl _wgetcwd (wchar_t*, int);
_CRTIMP wchar_t* __cdecl _wgetdcwd (int, wchar_t*, int);
_CRTIMP int __cdecl _wmkdir (const wchar_t*);
_CRTIMP int __cdecl _wrmdir (const wchar_t*);
#endif /* __MSVCRT__ */
#define _WDIRECT_DEFINED
#endif /* _WDIRECT_DEFINED */
#ifndef _STAT_DEFINED
/*
* The structure manipulated and returned by stat and fstat.
*
* NOTE: If called on a directory the values in the time fields are not only
* invalid, they will cause localtime et. al. to return NULL. And calling
* asctime with a NULL pointer causes an Invalid Page Fault. So watch it!
*/
struct _stat
{
_dev_t st_dev; /* Equivalent to drive number 0=A 1=B ... */
_ino_t st_ino; /* Always zero ? */
_mode_t st_mode; /* See above constants */
short st_nlink; /* Number of links. */
short st_uid; /* User: Maybe significant on NT ? */
short st_gid; /* Group: Ditto */
_dev_t st_rdev; /* Seems useless (not even filled in) */
_off_t st_size; /* File size in bytes */
time_t st_atime; /* Accessed date (always 00:00 hrs local
* on FAT) */
time_t st_mtime; /* Modified time */
time_t st_ctime; /* Creation time */
};
struct stat
{
_dev_t st_dev; /* Equivalent to drive number 0=A 1=B ... */
_ino_t st_ino; /* Always zero ? */
_mode_t st_mode; /* See above constants */
short st_nlink; /* Number of links. */
short st_uid; /* User: Maybe significant on NT ? */
short st_gid; /* Group: Ditto */
_dev_t st_rdev; /* Seems useless (not even filled in) */
_off_t st_size; /* File size in bytes */
time_t st_atime; /* Accessed date (always 00:00 hrs local
* on FAT) */
time_t st_mtime; /* Modified time */
time_t st_ctime; /* Creation time */
};
#if defined (__MSVCRT__)
struct _stati64 {
_dev_t st_dev;
_ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
__int64 st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
};
struct __stat64
{
_dev_t st_dev;
_ino_t st_ino;
_mode_t st_mode;
short st_nlink;
short st_uid;
short st_gid;
_dev_t st_rdev;
_off_t st_size;
__time64_t st_atime;
__time64_t st_mtime;
__time64_t st_ctime;
};
#endif /* __MSVCRT__ */
#define _STAT_DEFINED
#endif /* _STAT_DEFINED */
#if !defined ( _WSTAT_DEFINED)
/* also declared in sys/stat.h */
#if defined __MSVCRT__
_CRTIMP int __cdecl _wstat (const wchar_t*, struct _stat*);
_CRTIMP int __cdecl _wstati64 (const wchar_t*, struct _stati64*);
#if __MSVCRT_VERSION__ >= 0x0601
_CRTIMP int __cdecl _wstat64 (const wchar_t*, struct __stat64*);
#endif /* __MSVCRT_VERSION__ >= 0x0601 */
#endif /* __MSVCRT__ */
#define _WSTAT_DEFINED
#endif /* ! _WSTAT_DEFIND */
#ifndef _WLOCALE_DEFINED /* also declared in locale.h */
_CRTIMP wchar_t* __cdecl _wsetlocale (int, const wchar_t*);
#define _WLOCALE_DEFINED
#endif
#endif /* not __STRICT_ANSI__ */
#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif /* Not RC_INVOKED */
#endif /* not _WCHAR_H_ */
3.wctype.h
/*
* wctype.h
*
* Functions for testing wide character types and converting characters.
*
* This file is part of the Mingw32 package.
*
* Contributors:
* Created by Mumit Khan <khan@xraylith.wisc.edu>
*
* THIS SOFTWARE IS NOT COPYRIGHTED
*
* This source code is offered for use in the public domain. You may
* use, modify or distribute it freely.
*
* This code is distributed in the hope that it will be useful but
* WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
* DISCLAIMED. This includes but is not limited to warranties of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
*/
#ifndef _WCTYPE_H_
#define _WCTYPE_H_
/* All the headers include this file. */
#include <_mingw.h>
#define __need_wchar_t
#define __need_wint_t
#ifndef RC_INVOKED
#include <stddef.h>
#endif /* Not RC_INVOKED */
/*
* The following flags are used to tell iswctype and _isctype what character
* types you are looking for.
*/
#define _UPPER 0x0001
#define _LOWER 0x0002
#define _DIGIT 0x0004
#define _SPACE 0x0008
#define _PUNCT 0x0010
#define _CONTROL 0x0020
#define _BLANK 0x0040
#define _HEX 0x0080
#define _LEADBYTE 0x8000
#define _ALPHA 0x0103
#ifndef RC_INVOKED
#ifdef __cplusplus
extern "C" {
#endif
#ifndef WEOF
#define WEOF (wchar_t)(0xFFFF)
#endif
#ifndef _WCTYPE_T_DEFINED
typedef wchar_t wctype_t;
#define _WCTYPE_T_DEFINED
#endif
/* Wide character equivalents - also in ctype.h */
_CRTIMP int __cdecl iswalnum(wint_t);
_CRTIMP int __cdecl iswalpha(wint_t);
_CRTIMP int __cdecl iswascii(wint_t);
_CRTIMP int __cdecl iswcntrl(wint_t);
_CRTIMP int __cdecl iswctype(wint_t, wctype_t);
_CRTIMP int __cdecl is_wctype(wint_t, wctype_t); /* Obsolete! */
_CRTIMP int __cdecl iswdigit(wint_t);
_CRTIMP int __cdecl iswgraph(wint_t);
_CRTIMP int __cdecl iswlower(wint_t);
_CRTIMP int __cdecl iswprint(wint_t);
_CRTIMP int __cdecl iswpunct(wint_t);
_CRTIMP int __cdecl iswspace(wint_t);
_CRTIMP int __cdecl iswupper(wint_t);
_CRTIMP int __cdecl iswxdigit(wint_t);
_CRTIMP wchar_t __cdecl towlower(wchar_t);
_CRTIMP wchar_t __cdecl towupper(wchar_t);
_CRTIMP int __cdecl isleadbyte (int);
/* Also in ctype.h */
#ifdef __DECLSPEC_SUPPORTED
__MINGW_IMPORT unsigned short _ctype[];
# ifdef __MSVCRT__
__MINGW_IMPORT unsigned short* _pctype;
# else /* CRTDLL */
__MINGW_IMPORT unsigned short* _pctype_dll;
# define _pctype _pctype_dll
# endif
#else /* ! __DECLSPEC_SUPPORTED */
extern unsigned short** _imp___ctype;
#define _ctype (*_imp___ctype)
# ifdef __MSVCRT__
extern unsigned short** _imp___pctype;
# define _pctype (*_imp___pctype)
# else /* CRTDLL */
extern unsigned short** _imp___pctype_dll;
# define _pctype (*_imp___pctype_dll)
# endif /* CRTDLL */
#endif /* __DECLSPEC_SUPPORTED */
#if !(defined (__NO_INLINE__) || defined(__NO_CTYPE_INLINES) \
|| defined(__WCTYPE_INLINES_DEFINED))
#define __WCTYPE_INLINES_DEFINED
__CRT_INLINE int __cdecl iswalnum(wint_t wc) {return (iswctype(wc,_ALPHA|_DIGIT));}
__CRT_INLINE int __cdecl iswalpha(wint_t wc) {return (iswctype(wc,_ALPHA));}
__CRT_INLINE int __cdecl iswascii(wint_t wc) {return ((wc & ~0x7F) ==0);}
__CRT_INLINE int __cdecl iswcntrl(wint_t wc) {return (iswctype(wc,_CONTROL));}
__CRT_INLINE int __cdecl iswdigit(wint_t wc) {return (iswctype(wc,_DIGIT));}
__CRT_INLINE int __cdecl iswgraph(wint_t wc) {return (iswctype(wc,_PUNCT|_ALPHA|_DIGIT));}
__CRT_INLINE int __cdecl iswlower(wint_t wc) {return (iswctype(wc,_LOWER));}
__CRT_INLINE int __cdecl iswprint(wint_t wc) {return (iswctype(wc,_BLANK|_PUNCT|_ALPHA|_DIGIT));}
__CRT_INLINE int __cdecl iswpunct(wint_t wc) {return (iswctype(wc,_PUNCT));}
__CRT_INLINE int __cdecl iswspace(wint_t wc) {return (iswctype(wc,_SPACE));}
__CRT_INLINE int __cdecl iswupper(wint_t wc) {return (iswctype(wc,_UPPER));}
__CRT_INLINE int __cdecl iswxdigit(wint_t wc) {return (iswctype(wc,_HEX));}
__CRT_INLINE int __cdecl isleadbyte(int c) {return (_pctype[(unsigned char)(c)] & _LEADBYTE);}
#endif /* !(defined(__NO_CTYPE_INLINES) || defined(__WCTYPE_INLINES_DEFINED)) */
typedef wchar_t wctrans_t;
_CRTIMP wint_t __cdecl towctrans(wint_t, wctrans_t);
_CRTIMP wctrans_t __cdecl wctrans(const char*);
_CRTIMP wctype_t __cdecl wctype(const char*);
#ifdef __cplusplus
}
#endif
#endif /* Not RC_INVOKED */
#endif /* Not _WCTYPE_H_ */
-----------------------------------------------------------------------------------------------------
后来C99又增加了6标准库头文件,由于不常用,就不详细列出其源码了,这六个分别是
1.complex.h
2.fenv.h
3.inttypes.h
4.stdbool.h
5.stdint.h
6. tgmath.h
分类:
下面用红色字体,做部分解释:
1
/**/
/***
2*crt0.c - C runtime initialization routine
3*
4* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* This the actual startup routine for apps. It calls the user's main
8* routine [w]main() or [w]WinMain after performing C Run-Time Library
9* initialization.
10*
11* (With ifdef's, this source file also provides the source code for
12* wcrt0.c, the startup routine for console apps with wide characters,
13* wincrt0.c, the startup routine for Windows apps, and wwincrt0.c,
14* the startup routine for Windows apps with wide characters.)
15*
16*******************************************************************************/
17
18
#ifdef _WIN32
19
20
#ifndef CRTDLL
21
22
#include
<
cruntime.h
>
23
#include
<
dos.h
>
24
#include
<
internal
.h
>
25
#include
<
stdlib.h
>
26
#include
<
string
.h
>
27
#include
<
rterr.h
>
28
#include
<
windows.h
>
29
#include
<
awint.h
>
30
#include
<
tchar.h
>
31
#include
<
dbgint.h
>
32
33
/**/
/*
34 * wWinMain is not yet defined in winbase.h. When it is, this should be
35 * removed.
36 */
37
38
int
39
WINAPI
40
wWinMain(
41
HINSTANCE hInstance,
42
HINSTANCE hPrevInstance,
43
LPWSTR lpCmdLine,
44
int
nShowCmd
45
);
46
47
#ifdef WPRFLAG
48
_TUCHAR
*
__cdecl _wwincmdln(
void
);
49
#else
/* WPRFLAG */
50
_TUCHAR
*
__cdecl _wincmdln(
void
);
51
#endif
/* WPRFLAG */
52
53
/**/
/*
54 * command line, environment, and a few other globals
55 */
56
57
#ifdef WPRFLAG
58
wchar_t
*
_wcmdln;
/**/
/* points to wide command line */
59
#else
/* WPRFLAG */
60
char
*
_acmdln;
/**/
/* points to command line */
61
#endif
/* WPRFLAG */
62
63
char
*
_aenvptr
=
NULL;
/**/
/* points to environment block */
64
wchar_t
*
_wenvptr
=
NULL;
/**/
/* points to wide environment block */
65
66
67
void
(__cdecl
*
_aexit_rtn)(
int
)
=
_exit;
/**/
/* RT message return procedure */
68
69
static
void
__cdecl fast_error_exit(
int
);
/**/
/* Error exit via ExitProcess */
70
71
/**/
/*
72 * _error_mode and _apptype, together, determine how error messages are
73 * written out.
74 */
75
int
__error_mode
=
_OUT_TO_DEFAULT;
76
#ifdef _WINMAIN_
77
int
__app_type
=
_GUI_APP;
78
#else
/* _WINMAIN_ */
79
int
__app_type
=
_CONSOLE_APP;
80
#endif
/* _WINMAIN_ */
81
82
83
/**/
/***
84*BaseProcessStartup(PVOID Peb)
85*
86*Purpose:
87* This routine does the C runtime initialization, calls main(), and
88* then exits. It never returns.
89*
90*Entry:
91* PVOID Peb - pointer to Win32 Process Environment Block (not used)
92*
93*Exit:
94* This function never returns.
95*
96*******************************************************************************/
97
98
#ifdef _WINMAIN_
99
100
#ifdef WPRFLAG
101
void
wWinMainCRTStartup(
102
#else
/* WPRFLAG */
103
void
WinMainCRTStartup(
104
#endif
/* WPRFLAG */
105
106
#else
/* _WINMAIN_ */
107
108
#ifdef WPRFLAG
109
void
wmainCRTStartup(
110
#else
/* WPRFLAG */
111
void
mainCRTStartup(
112
#endif
/* WPRFLAG */
113
114
#endif
/* _WINMAIN_ */
115
void
116
)
117
118
{
119 int mainret;
120
121#ifdef _WINMAIN_
122 _TUCHAR *lpszCommandLine;
123 STARTUPINFO StartupInfo;
124#endif /* _WINMAIN_ */
125
126 /**//*
127 * Get the full Win32 version
128 */
129 _osver = GetVersion();
130
131 _winminor = (_osver >> 8) & 0x00FF ;
132 _winmajor = _osver & 0x00FF ;
133 _winver = (_winmajor << 8) + _winminor;
134 _osver = (_osver >> 16) & 0x00FFFF ;
135
136#ifdef _MT
137 if ( !_heap_init(1) ) /**//* initialize heap */
138#else /* _MT */
139 if ( !_heap_init(0) ) /**//* initialize heap */
140#endif /* _MT */
141 fast_error_exit(_RT_HEAPINIT); /**//* write message and die */
142
143#ifdef _MT
144 if( !_mtinit() ) /**//* initialize multi-thread */
145 fast_error_exit(_RT_THREAD); /**//* write message and die */
146#endif /* _MT */
147
148 /**//*
149 * Guard the remainder of the initialization code and the call
150 * to user's main, or WinMain, function in a __try/__except
151 * statement.
152 */
153
154 __try {
155
156 _ioinit(); /**//* initialize lowio */
157
158#ifdef WPRFLAG
159 /**//* get wide cmd line info */
160 _wcmdln = (wchar_t *)__crtGetCommandLineW();
161
162 /**//* get wide environ info */
163 _wenvptr = (wchar_t *)__crtGetEnvironmentStringsW();
164
165 _wsetargv();
166 _wsetenvp();
167#else /* WPRFLAG */
168 /**//* get cmd line info */
169 _acmdln = (char *)GetCommandLineA();
170
171 /**//* get environ info */
172 _aenvptr = (char *)__crtGetEnvironmentStringsA();
173
174 _setargv();
175 _setenvp();
176#endif /* WPRFLAG */
177
178 _cinit(); /**//* do C data initialize */
179
180#ifdef _WINMAIN_
181
182 StartupInfo.dwFlags = 0;
183 GetStartupInfo( &StartupInfo );
184
185#ifdef WPRFLAG
186 lpszCommandLine = _wwincmdln();
187 mainret = wWinMain(
188#else /* WPRFLAG */
189 lpszCommandLine = _wincmdln();
190 mainret = WinMain(
191#endif /* WPRFLAG */
192 GetModuleHandleA(NULL),
193 NULL,
194 lpszCommandLine,
195 StartupInfo.dwFlags & STARTF_USESHOWWINDOW
196 ? StartupInfo.wShowWindow
197 : SW_SHOWDEFAULT
198 );
199#else /* _WINMAIN_ */
200
201#ifdef WPRFLAG
202 __winitenv = _wenviron;
203 mainret = wmain(__argc, __wargv, _wenviron);
204#else /* WPRFLAG */
205 __initenv = _environ;
206 mainret = main(__argc, __argv, _environ);
207#endif /* WPRFLAG */
208
209#endif /* _WINMAIN_ */
210 exit(mainret);
211 }
212 __except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
213 {
214 /**//*
215 * Should never reach here
216 */
217 _exit( GetExceptionCode() );
218
219 } /**//* end of try - except */
220
221}
222
223
224
225
/**/
/***
226*_amsg_exit(rterrnum) - Fast exit fatal errors
227*
228*Purpose:
229* Exit the program with error code of 255 and appropriate error
230* message.
231*
232*Entry:
233* int rterrnum - error message number (amsg_exit only).
234*
235*Exit:
236* Calls exit() (for integer divide-by-0) or _exit() indirectly
237* through _aexit_rtn [amsg_exit].
238* For multi-thread: calls _exit() function
239*
240*Exceptions:
241*
242*******************************************************************************/
243
244
void
__cdecl _amsg_exit (
245
int
rterrnum
246
)
247
{
248#ifdef _WINMAIN_
249 if ( __error_mode == _OUT_TO_STDERR )
250#else /* _WINMAIN_ */
251 if ( __error_mode != _OUT_TO_MSGBOX )
252#endif /* _WINMAIN_ */
253 _FF_MSGBANNER(); /**//* write run-time error banner */
254
255 _NMSG_WRITE(rterrnum); /**//* write message */
256 _aexit_rtn(255); /**//* normally _exit(255) */
257}
258
259
/**/
/***
260*fast_error_exit(rterrnum) - Faster exit fatal errors
261*
262*Purpose:
263* Exit the process with error code of 255 and appropriate error
264* message.
265*
266*Entry:
267* int rterrnum - error message number (amsg_exit only).
268*
269*Exit:
270* Calls ExitProcess.
271*
272*Exceptions:
273*
274*******************************************************************************/
275
276
static
void
__cdecl fast_error_exit (
277
int
rterrnum
278
)
279
{
280#ifdef _WINMAIN_
281 if ( __error_mode == _OUT_TO_STDERR )
282#else /* _WINMAIN_ */
283 if ( __error_mode != _OUT_TO_MSGBOX )
284#endif /* _WINMAIN_ */
285 _FF_MSGBANNER(); /**//* write run-time error banner */
286
287 _NMSG_WRITE(rterrnum); /**//* write message */
288 ExitProcess(255); /**//* normally _exit(255) */
289}
290
291
#ifndef WPRFLAG
292
293
294
#endif
/* WPRFLAG */
295
296
#endif
/* CRTDLL */
297
298
#else
/* _WIN32 */
299
300
#include
<
cruntime.h
>
301
#include
<
internal
.h
>
302
#include
<
stdlib.h
>
303
#include
<
msdos.h
>
304
#include
<
string
.h
>
305
#include
<
setjmp.h
>
306
#include
<
dbgint.h
>
307
#include
<
macos\types.h
>
308
#include
<
macos\segload.h
>
309
#include
<
macos\gestalte.h
>
310
#include
<
macos\osutils.h
>
311
#include
<
macos\traps.h
>
312
#include
<
mpw.h
>
313
314
static
void
__cdecl Inherit(
void
);
/**/
/* local function */
315
316
int
__cdecl main(
int
,
char
**
,
char
**
);
/**/
/*generated by compiler*/
317
318
unsigned
long
_GetShellStack(
void
);
319
320
static
char
*
__cdecl _p2cstr_internal ( unsigned
char
*
str );
321
322
extern
MPWBLOCK
*
_pMPWBlock;
323
extern
int
__argc;
324
extern
char
**
__argv;
325
326
/**/
/***
327*__crt0()
328*
329*Purpose:
330* This routine does the C runtime initialization, calls main(), and
331* then exits. It never returns.
332*
333*Entry:
334*
335*Exit:
336* This function never returns.
337*
338*******************************************************************************/
339
340
void
__cdecl __crt0 (
341
)
342
{
343 int mainret;
344 char szPgmName[32];
345 char *pArg;
346 char *argv[2];
347
348#ifndef _M_MPPC
349 void *pv;
350
351 /**//* This is the magic stuff that MPW tools do to get info from MPW*/
352
353 pv = (void *)*(int *)0x316;
354 if (pv != NULL && !((int)pv & 1) && *(int *)pv == 'MPGM') {
355 pv = (void *)*++(int *)pv;
356 if (pv != NULL && *(short *)pv == 'SH') {
357 _pMPWBlock = (MPWBLOCK *)pv;
358 }
359 }
360
361#endif /* _M_MPPC */
362
363 _environ = NULL;
364 if (_pMPWBlock == NULL) {
365 __argc = 1;
366 memcpy(szPgmName, (char *)0x910, sizeof(szPgmName));
367 pArg = _p2cstr_internal(szPgmName);
368 argv[0] = pArg;
369 argv[1] = NULL;
370 __argv = argv;
371
372#ifndef _M_MPPC
373 _shellStack = 0; /**//* force ExitToShell */
374#endif /* _M_MPPC */
375 }
376#ifndef _M_MPPC
377 else {
378 _shellStack = _GetShellStack(); //return current a6, or first a6
379 _shellStack += 4; //a6 + 4 is the stack pointer we want
380 __argc = _pMPWBlock->argc;
381 __argv = _pMPWBlock->argv;
382
383 Inherit(); /**//* Inherit file handles - env is set up by _envinit if needed */
384 }
385#endif /* _M_MPPC */
386
387 /**//*
388 * call run time initializer
389 */
390 __cinit();
391
392 mainret = main(__argc, __argv, _environ);
393 exit(mainret);
394}
395
396
397
#ifndef _M_MPPC
398
/**/
/***
399*Inherit() - obtain and process info on inherited file handles.
400*
401*Purpose:
402*
403* Locates and interprets MPW std files. For files we just save the
404* file handles. For the console we save the device table address so
405* we can do console I/O. In the latter case, FDEV is set in the _osfile
406* array.
407*
408*Entry:
409* Address of MPW param table
410*
411*Exit:
412* No return value.
413*
414*Exceptions:
415*
416*******************************************************************************/
417
418
static
void
__cdecl Inherit (
419
void
420
)
421
{
422 MPWFILE *pFile;
423 int i;
424 pFile = _pMPWBlock->pFile;
425 if (pFile == NULL) {
426 return;
427 }
428 for (i = 0; i < 3; i++) {
429 switch ((pFile->pDevice)->name) {
430 case 'ECON':
431 _osfile[i] |= FDEV | FOPEN;
432 _osfhnd[i] = (int)pFile;
433 break;
434
435 case 'FSYS':
436 _osfile[i] |= FOPEN;
437 _osfhnd[i] = (*(pFile->ppFInfo))->ioRefNum;
438 break;
439 }
440 pFile++;
441 }
442}
443
444
#endif
/* _M_MPPC */
445
446
447
448
static
char
*
__cdecl _p2cstr_internal (
449
unsigned
char
*
str
450
)
451
{
452 unsigned char *pchSrc;
453 unsigned char *pchDst;
454 int cch;
455
456 if ( str && *str ) {
457 pchDst = str;
458 pchSrc = str + 1;
459
460 for ( cch=*pchDst; cch; --cch ) {
461 *pchDst++ = *pchSrc++;
462 }
463
464 *pchDst = '\0';
465 }
466
467 return( str );
468}
469
470
#endif
/* _WIN32 */
471
1. 应用程序类型--------只有2类:要么是CUI, 要么是GUI
2. 程序真正的启动代码(入口点函数)-----------各种**CRTStartUp
3. 环境变量+命令行信息的相关变量和函数都在此文件中有定义或声明
4. 调用运行时初始化+main()函数的最后返回和报错信息在下面的代码定义了
1
*******************************************************************************/
2
3
void
__cdecl __crt0 (
4
)
5
{
6 int mainret;
7 char szPgmName[32];
8 char *pArg;
9 char *argv[2];
10
11#ifndef _M_MPPC
12 void *pv;
13
14 /**//* This is the magic stuff that MPW tools do to get info from MPW*/
15
16 pv = (void *)*(int *)0x316;
17 if (pv != NULL && !((int)pv & 1) && *(int *)pv == 'MPGM') {
18 pv = (void *)*++(int *)pv;
19 if (pv != NULL && *(short *)pv == 'SH') {
20 _pMPWBlock = (MPWBLOCK *)pv;
21 }
22 }
23
24#endif /* _M_MPPC */
25
26 _environ = NULL;
27 if (_pMPWBlock == NULL) {
28 __argc = 1;
29 memcpy(szPgmName, (char *)0x910, sizeof(szPgmName));
30 pArg = _p2cstr_internal(szPgmName);
31 argv[0] = pArg;
32 argv[1] = NULL;
33 __argv = argv;
34
35#ifndef _M_MPPC
36 _shellStack = 0; /**//* force ExitToShell */
37#endif /* _M_MPPC */
38 }
39#ifndef _M_MPPC
40 else {
41 _shellStack = _GetShellStack(); //return current a6, or first a6
42 _shellStack += 4; //a6 + 4 is the stack pointer we want
43 __argc = _pMPWBlock->argc;
44 __argv = _pMPWBlock->argv;
45
46 Inherit(); /**//* Inherit file handles - env is set up by _envinit if needed */
47 }
48#endif /* _M_MPPC */
49
50 /**//*
51 * call run time initializer
52 */
53 __cinit();
54
55 mainret = main(__argc, __argv, _environ);
56 exit(mainret);
57}
58
59
5. 获取进程信息+响应中断的代码如下:
1
/**/
/***
2*Inherit() - obtain and process info on inherited file handles.
3*
4*Purpose:
5*
6* Locates and interprets MPW std files. For files we just save the
7* file handles. For the console we save the device table address so
8* we can do console I/O. In the latter case, FDEV is set in the _osfile
9* array.
10*
11*Entry:
12* Address of MPW param table
13*
14*Exit:
15* No return value.
16*
17*Exceptions:
18*
19*******************************************************************************/
20
21
static
void
__cdecl Inherit (
22
void
23
)
24
{
25 MPWFILE *pFile;
26 int i;
27 pFile = _pMPWBlock->pFile;
28 if (pFile == NULL) {
29 return;
30 }
31 for (i = 0; i < 3; i++) {
32 switch ((pFile->pDevice)->name) {
33 case 'ECON':
34 _osfile[i] |= FDEV | FOPEN;
35 _osfhnd[i] = (int)pFile;
36 break;
37
38 case 'FSYS':
39 _osfile[i] |= FOPEN;
40 _osfhnd[i] = (*(pFile->ppFInfo))->ioRefNum;
41 break;
42 }
43 pFile++;
44 }
45}
46
47
#endif
/* _M_MPPC */
48
49
50
51
static
char
*
__cdecl _p2cstr_internal (
52
unsigned
char
*
str
53
)
54
{
55 unsigned char *pchSrc;
56 unsigned char *pchDst;
57 int cch;
58
59 if ( str && *str ) {
60 pchDst = str;
61 pchSrc = str + 1;
62
63 for ( cch=*pchDst; cch; --cch ) {
64 *pchDst++ = *pchSrc++;
65 }
66
67 *pchDst = '\0';
68 }
69
70 return( str );
71}
72
73
#endif
/* _WIN32 */
6. 如果是GUI程序,则要创建“内核对象”,请参考下面的MSDN中的STARTUPINFO结构体的说明
http://www.cnblogs.com/shanzy/articles/513455.html
7. 上面的crt0.c文件中涉及到MS针对不同的CPU厂商都能够跑MS的VC编译器的CPU假设,如下面MSDN文章所说------------当然,你也可以在代码中手写下面这些MS预定义宏,或者写MAKEFILE
Predefined Macros
The compiler recognizes six predefined ANSI C macros (see Table 1.1), and the Microsoft C++ implementation provides several more (see Table 1.2). These macros take no arguments and cannot be redefined. Their value (except for __LINE__ and __FILE__) must be constant throughout compilation. Some of the predefined macros listed below are defined with multiple values. Their values can be set by selecting the corresponding menu option in the Visual C++ development environment, or by using a command-line switch. See the tables below for more information.
Table 1.1 ANSI Predefined Macros
Macro Description __DATE__ The compilation date of the current source file. The date is a string literal of the form Mmm dd yyyy. The month name Mmm is the same as for dates generated by the library function asctime declared in TIME.H. __FILE__ The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks. __LINE__ The line number in the current source file. The line number is a decimal integer constant. It can be altered with a #line directive. __STDC__ Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined. __TIME__ The most recent compilation time of the current source file. The time is a string literal of the form hh:mm:ss. __TIMESTAMP__ The date and time of the last modification of the current source file, expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, where Ddd is the abbreviated day of the week and Date is an integer from 1 to 31.
Table 1.2 Microsoft-Specific Predefined Macros
Macro Description _CHAR_UNSIGNED Default char type is unsigned. Defined when /J is specified. __cplusplus Defined for C++ programs only. _CPPRTTI Defined for code compiled with /GR (Enable Run-Time Type Information). _CPPUNWIND Defined for code compiled with /GX (Enable Exception Handling). _DLL Defined when /MD or /MDd (Multithread DLL) is specified. _M_ALPHA Defined for DEC ALPHA platforms. It is defined as 1 by the ALPHA compiler, and it is not defined if another compiler is used. _M_IX86 Defined for x86 processors. See Table 1.3 for more details. _M_MPPC Defined for Power Macintosh platforms. Default is 601 (/QP601). See Table 1.4 for more details. _M_MRX000 Defined for MIPS platforms. Default is 4000 (/QMR4000). See Table 1.5 for more details. _M_PPC Defined for PowerPC platforms. Default is 604 (/QP604). See Table 1.6 for more details. _MFC_VER Defines the MFC version. Defined as 0x0421 for Microsoft Foundation Class Library 4.21. Always defined. _MSC_EXTENSIONS This macro is defined when compiling with the /Ze compiler option (the default). Its value, when defined, is 1. _MSC_VER Defines the compiler version. Defined as 1200 for Microsoft Visual C++ 6.0. Always defined. _MT Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd(Multithreaded) is specified. _WIN32 Defined for applications for Win32®. Always defined.
As shown in following tables, the compiler generates a value for the preprocessor identifiers that reflect the processor option specified.
Option in Developer Studio Command-Line Option Resulting Value Blend /GB _M_IX86 = 500 (Default. Future compilers will emit a different value to reflect the dominant processor.) Pentium /G5 _M_IX86 = 500 Pentium Pro /G6 _M_IX86 = 600 80386 /G3 _M_IX86 = 300 80486 /G4 _M_IX86 = 400
Option in development environment Command-Line Option Resulting Value PowerPC 601 /QP601 _M_MPPC = 601 (Default) PowerPC 603 /QP603 _M_MPPC = 603 PowerPC 604 /QP604 _M_MPPC = 604 PowerPC 620 /QP620 _M_MPPC = 620
Table 1.5 Values for _M_MRX000
Option in Developer Studio Command-Line Option Resulting Value R4000 /QMR4000 _M_MRX000 = 4000 (Default) R4100 /QMR4100 _M_MRX000 = 4100 R4200 /QMR4200 _M_MRX000 = 4200 R4400 /QMR4400 _M_MRX000 = 4400 R4600 /QMR4600 _M_MRX000 = 4600 R10000 /QMR10000 _M_MRX000 = 10000
Option in Developer Studio Command-Line Option Resulting Value PowerPC 601 /QP601 _M_PPC = 601 PowerPC 603 /QP603 _M_PPC = 603 PowerPC 604 /QP604 _M_PPC = 604 (Default) PowerPC 620 /QP620 _M_PPC = 620
8. 任何C/C++编译器的构造,都是依托于ANSI C/ANSI C++标准的,但是,由于某些历史问题当ANSI标准影响了厂商的标准,或者厂商认为某些东西更利于开发的时候,厂商会在ANSI标准提供的编译器的基础上对CRT运行时库进行扩充,扩充的结果就是上面的情况
9. 厂商扩充了ANSI标准,就需要写出一个自己的编译器(MS 的VC编译器就是cl.exe),写这个cl.exe的过程要根据厂商扩充之后的各种标准表格,在写这个cl.exe的时候做出很多的选择分支(当然,MS这里用它认为重要的一些“自定义宏”来写它的cl.exe)
2*crt0.c - C runtime initialization routine
3*
4* Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
5*
6*Purpose:
7* This the actual startup routine for apps. It calls the user's main
8* routine [w]main() or [w]WinMain after performing C Run-Time Library
9* initialization.
10*
11* (With ifdef's, this source file also provides the source code for
12* wcrt0.c, the startup routine for console apps with wide characters,
13* wincrt0.c, the startup routine for Windows apps, and wwincrt0.c,
14* the startup routine for Windows apps with wide characters.)
15*
16*******************************************************************************/
17
18 #ifdef _WIN32
19
20 #ifndef CRTDLL
21
22 #include < cruntime.h >
23 #include < dos.h >
24 #include < internal .h >
25 #include < stdlib.h >
26 #include < string .h >
27 #include < rterr.h >
28 #include < windows.h >
29 #include < awint.h >
30 #include < tchar.h >
31 #include < dbgint.h >
32
33 /**/ /*
34 * wWinMain is not yet defined in winbase.h. When it is, this should be
35 * removed.
36 */
37
38 int
39 WINAPI
40 wWinMain(
41 HINSTANCE hInstance,
42 HINSTANCE hPrevInstance,
43 LPWSTR lpCmdLine,
44 int nShowCmd
45 );
46
47 #ifdef WPRFLAG
48 _TUCHAR * __cdecl _wwincmdln( void );
49 #else /* WPRFLAG */
50 _TUCHAR * __cdecl _wincmdln( void );
51 #endif /* WPRFLAG */
52
53 /**/ /*
54 * command line, environment, and a few other globals
55 */
56
57 #ifdef WPRFLAG
58 wchar_t * _wcmdln; /**/ /* points to wide command line */
59 #else /* WPRFLAG */
60 char * _acmdln; /**/ /* points to command line */
61 #endif /* WPRFLAG */
62
63 char * _aenvptr = NULL; /**/ /* points to environment block */
64 wchar_t * _wenvptr = NULL; /**/ /* points to wide environment block */
65
66
67 void (__cdecl * _aexit_rtn)( int ) = _exit; /**/ /* RT message return procedure */
68
69 static void __cdecl fast_error_exit( int ); /**/ /* Error exit via ExitProcess */
70
71 /**/ /*
72 * _error_mode and _apptype, together, determine how error messages are
73 * written out.
74 */
75 int __error_mode = _OUT_TO_DEFAULT;
76 #ifdef _WINMAIN_
77 int __app_type = _GUI_APP;
78 #else /* _WINMAIN_ */
79 int __app_type = _CONSOLE_APP;
80 #endif /* _WINMAIN_ */
81
82
83 /**/ /***
84*BaseProcessStartup(PVOID Peb)
85*
86*Purpose:
87* This routine does the C runtime initialization, calls main(), and
88* then exits. It never returns.
89*
90*Entry:
91* PVOID Peb - pointer to Win32 Process Environment Block (not used)
92*
93*Exit:
94* This function never returns.
95*
96*******************************************************************************/
97
98 #ifdef _WINMAIN_
99
100 #ifdef WPRFLAG
101 void wWinMainCRTStartup(
102 #else /* WPRFLAG */
103 void WinMainCRTStartup(
104 #endif /* WPRFLAG */
105
106 #else /* _WINMAIN_ */
107
108 #ifdef WPRFLAG
109 void wmainCRTStartup(
110 #else /* WPRFLAG */
111 void mainCRTStartup(
112 #endif /* WPRFLAG */
113
114 #endif /* _WINMAIN_ */
115 void
116 )
117
118 {
119 int mainret;
120
121#ifdef _WINMAIN_
122 _TUCHAR *lpszCommandLine;
123 STARTUPINFO StartupInfo;
124#endif /* _WINMAIN_ */
125
126 /**//*
127 * Get the full Win32 version
128 */
129 _osver = GetVersion();
130
131 _winminor = (_osver >> 8) & 0x00FF ;
132 _winmajor = _osver & 0x00FF ;
133 _winver = (_winmajor << 8) + _winminor;
134 _osver = (_osver >> 16) & 0x00FFFF ;
135
136#ifdef _MT
137 if ( !_heap_init(1) ) /**//* initialize heap */
138#else /* _MT */
139 if ( !_heap_init(0) ) /**//* initialize heap */
140#endif /* _MT */
141 fast_error_exit(_RT_HEAPINIT); /**//* write message and die */
142
143#ifdef _MT
144 if( !_mtinit() ) /**//* initialize multi-thread */
145 fast_error_exit(_RT_THREAD); /**//* write message and die */
146#endif /* _MT */
147
148 /**//*
149 * Guard the remainder of the initialization code and the call
150 * to user's main, or WinMain, function in a __try/__except
151 * statement.
152 */
153
154 __try {
155
156 _ioinit(); /**//* initialize lowio */
157
158#ifdef WPRFLAG
159 /**//* get wide cmd line info */
160 _wcmdln = (wchar_t *)__crtGetCommandLineW();
161
162 /**//* get wide environ info */
163 _wenvptr = (wchar_t *)__crtGetEnvironmentStringsW();
164
165 _wsetargv();
166 _wsetenvp();
167#else /* WPRFLAG */
168 /**//* get cmd line info */
169 _acmdln = (char *)GetCommandLineA();
170
171 /**//* get environ info */
172 _aenvptr = (char *)__crtGetEnvironmentStringsA();
173
174 _setargv();
175 _setenvp();
176#endif /* WPRFLAG */
177
178 _cinit(); /**//* do C data initialize */
179
180#ifdef _WINMAIN_
181
182 StartupInfo.dwFlags = 0;
183 GetStartupInfo( &StartupInfo );
184
185#ifdef WPRFLAG
186 lpszCommandLine = _wwincmdln();
187 mainret = wWinMain(
188#else /* WPRFLAG */
189 lpszCommandLine = _wincmdln();
190 mainret = WinMain(
191#endif /* WPRFLAG */
192 GetModuleHandleA(NULL),
193 NULL,
194 lpszCommandLine,
195 StartupInfo.dwFlags & STARTF_USESHOWWINDOW
196 ? StartupInfo.wShowWindow
197 : SW_SHOWDEFAULT
198 );
199#else /* _WINMAIN_ */
200
201#ifdef WPRFLAG
202 __winitenv = _wenviron;
203 mainret = wmain(__argc, __wargv, _wenviron);
204#else /* WPRFLAG */
205 __initenv = _environ;
206 mainret = main(__argc, __argv, _environ);
207#endif /* WPRFLAG */
208
209#endif /* _WINMAIN_ */
210 exit(mainret);
211 }
212 __except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
213 {
214 /**//*
215 * Should never reach here
216 */
217 _exit( GetExceptionCode() );
218
219 } /**//* end of try - except */
220
221}
222
223
224
225 /**/ /***
226*_amsg_exit(rterrnum) - Fast exit fatal errors
227*
228*Purpose:
229* Exit the program with error code of 255 and appropriate error
230* message.
231*
232*Entry:
233* int rterrnum - error message number (amsg_exit only).
234*
235*Exit:
236* Calls exit() (for integer divide-by-0) or _exit() indirectly
237* through _aexit_rtn [amsg_exit].
238* For multi-thread: calls _exit() function
239*
240*Exceptions:
241*
242*******************************************************************************/
243
244 void __cdecl _amsg_exit (
245 int rterrnum
246 )
247 {
248#ifdef _WINMAIN_
249 if ( __error_mode == _OUT_TO_STDERR )
250#else /* _WINMAIN_ */
251 if ( __error_mode != _OUT_TO_MSGBOX )
252#endif /* _WINMAIN_ */
253 _FF_MSGBANNER(); /**//* write run-time error banner */
254
255 _NMSG_WRITE(rterrnum); /**//* write message */
256 _aexit_rtn(255); /**//* normally _exit(255) */
257}
258
259 /**/ /***
260*fast_error_exit(rterrnum) - Faster exit fatal errors
261*
262*Purpose:
263* Exit the process with error code of 255 and appropriate error
264* message.
265*
266*Entry:
267* int rterrnum - error message number (amsg_exit only).
268*
269*Exit:
270* Calls ExitProcess.
271*
272*Exceptions:
273*
274*******************************************************************************/
275
276 static void __cdecl fast_error_exit (
277 int rterrnum
278 )
279 {
280#ifdef _WINMAIN_
281 if ( __error_mode == _OUT_TO_STDERR )
282#else /* _WINMAIN_ */
283 if ( __error_mode != _OUT_TO_MSGBOX )
284#endif /* _WINMAIN_ */
285 _FF_MSGBANNER(); /**//* write run-time error banner */
286
287 _NMSG_WRITE(rterrnum); /**//* write message */
288 ExitProcess(255); /**//* normally _exit(255) */
289}
290
291 #ifndef WPRFLAG
292
293
294 #endif /* WPRFLAG */
295
296 #endif /* CRTDLL */
297
298 #else /* _WIN32 */
299
300 #include < cruntime.h >
301 #include < internal .h >
302 #include < stdlib.h >
303 #include < msdos.h >
304 #include < string .h >
305 #include < setjmp.h >
306 #include < dbgint.h >
307 #include < macos\types.h >
308 #include < macos\segload.h >
309 #include < macos\gestalte.h >
310 #include < macos\osutils.h >
311 #include < macos\traps.h >
312 #include < mpw.h >
313
314 static void __cdecl Inherit( void ); /**/ /* local function */
315
316 int __cdecl main( int , char ** , char ** ); /**/ /*generated by compiler*/
317
318 unsigned long _GetShellStack( void );
319
320 static char * __cdecl _p2cstr_internal ( unsigned char * str );
321
322 extern MPWBLOCK * _pMPWBlock;
323 extern int __argc;
324 extern char ** __argv;
325
326 /**/ /***
327*__crt0()
328*
329*Purpose:
330* This routine does the C runtime initialization, calls main(), and
331* then exits. It never returns.
332*
333*Entry:
334*
335*Exit:
336* This function never returns.
337*
338*******************************************************************************/
339
340 void __cdecl __crt0 (
341 )
342 {
343 int mainret;
344 char szPgmName[32];
345 char *pArg;
346 char *argv[2];
347
348#ifndef _M_MPPC
349 void *pv;
350
351 /**//* This is the magic stuff that MPW tools do to get info from MPW*/
352
353 pv = (void *)*(int *)0x316;
354 if (pv != NULL && !((int)pv & 1) && *(int *)pv == 'MPGM') {
355 pv = (void *)*++(int *)pv;
356 if (pv != NULL && *(short *)pv == 'SH') {
357 _pMPWBlock = (MPWBLOCK *)pv;
358 }
359 }
360
361#endif /* _M_MPPC */
362
363 _environ = NULL;
364 if (_pMPWBlock == NULL) {
365 __argc = 1;
366 memcpy(szPgmName, (char *)0x910, sizeof(szPgmName));
367 pArg = _p2cstr_internal(szPgmName);
368 argv[0] = pArg;
369 argv[1] = NULL;
370 __argv = argv;
371
372#ifndef _M_MPPC
373 _shellStack = 0; /**//* force ExitToShell */
374#endif /* _M_MPPC */
375 }
376#ifndef _M_MPPC
377 else {
378 _shellStack = _GetShellStack(); //return current a6, or first a6
379 _shellStack += 4; //a6 + 4 is the stack pointer we want
380 __argc = _pMPWBlock->argc;
381 __argv = _pMPWBlock->argv;
382
383 Inherit(); /**//* Inherit file handles - env is set up by _envinit if needed */
384 }
385#endif /* _M_MPPC */
386
387 /**//*
388 * call run time initializer
389 */
390 __cinit();
391
392 mainret = main(__argc, __argv, _environ);
393 exit(mainret);
394}
395
396
397 #ifndef _M_MPPC
398 /**/ /***
399*Inherit() - obtain and process info on inherited file handles.
400*
401*Purpose:
402*
403* Locates and interprets MPW std files. For files we just save the
404* file handles. For the console we save the device table address so
405* we can do console I/O. In the latter case, FDEV is set in the _osfile
406* array.
407*
408*Entry:
409* Address of MPW param table
410*
411*Exit:
412* No return value.
413*
414*Exceptions:
415*
416*******************************************************************************/
417
418 static void __cdecl Inherit (
419 void
420 )
421 {
422 MPWFILE *pFile;
423 int i;
424 pFile = _pMPWBlock->pFile;
425 if (pFile == NULL) {
426 return;
427 }
428 for (i = 0; i < 3; i++) {
429 switch ((pFile->pDevice)->name) {
430 case 'ECON':
431 _osfile[i] |= FDEV | FOPEN;
432 _osfhnd[i] = (int)pFile;
433 break;
434
435 case 'FSYS':
436 _osfile[i] |= FOPEN;
437 _osfhnd[i] = (*(pFile->ppFInfo))->ioRefNum;
438 break;
439 }
440 pFile++;
441 }
442}
443
444 #endif /* _M_MPPC */
445
446
447
448 static char * __cdecl _p2cstr_internal (
449 unsigned char * str
450 )
451 {
452 unsigned char *pchSrc;
453 unsigned char *pchDst;
454 int cch;
455
456 if ( str && *str ) {
457 pchDst = str;
458 pchSrc = str + 1;
459
460 for ( cch=*pchDst; cch; --cch ) {
461 *pchDst++ = *pchSrc++;
462 }
463
464 *pchDst = '\0';
465 }
466
467 return( str );
468}
469
470 #endif /* _WIN32 */
471
1. 应用程序类型--------只有2类:要么是CUI, 要么是GUI
2. 程序真正的启动代码(入口点函数)-----------各种**CRTStartUp
3. 环境变量+命令行信息的相关变量和函数都在此文件中有定义或声明
4. 调用运行时初始化+main()函数的最后返回和报错信息在下面的代码定义了
2
3 void __cdecl __crt0 (
4 )
5 {
6 int mainret;
7 char szPgmName[32];
8 char *pArg;
9 char *argv[2];
10
11#ifndef _M_MPPC
12 void *pv;
13
14 /**//* This is the magic stuff that MPW tools do to get info from MPW*/
15
16 pv = (void *)*(int *)0x316;
17 if (pv != NULL && !((int)pv & 1) && *(int *)pv == 'MPGM') {
18 pv = (void *)*++(int *)pv;
19 if (pv != NULL && *(short *)pv == 'SH') {
20 _pMPWBlock = (MPWBLOCK *)pv;
21 }
22 }
23
24#endif /* _M_MPPC */
25
26 _environ = NULL;
27 if (_pMPWBlock == NULL) {
28 __argc = 1;
29 memcpy(szPgmName, (char *)0x910, sizeof(szPgmName));
30 pArg = _p2cstr_internal(szPgmName);
31 argv[0] = pArg;
32 argv[1] = NULL;
33 __argv = argv;
34
35#ifndef _M_MPPC
36 _shellStack = 0; /**//* force ExitToShell */
37#endif /* _M_MPPC */
38 }
39#ifndef _M_MPPC
40 else {
41 _shellStack = _GetShellStack(); //return current a6, or first a6
42 _shellStack += 4; //a6 + 4 is the stack pointer we want
43 __argc = _pMPWBlock->argc;
44 __argv = _pMPWBlock->argv;
45
46 Inherit(); /**//* Inherit file handles - env is set up by _envinit if needed */
47 }
48#endif /* _M_MPPC */
49
50 /**//*
51 * call run time initializer
52 */
53 __cinit();
54
55 mainret = main(__argc, __argv, _environ);
56 exit(mainret);
57}
58
59
5. 获取进程信息+响应中断的代码如下:
2*Inherit() - obtain and process info on inherited file handles.
3*
4*Purpose:
5*
6* Locates and interprets MPW std files. For files we just save the
7* file handles. For the console we save the device table address so
8* we can do console I/O. In the latter case, FDEV is set in the _osfile
9* array.
10*
11*Entry:
12* Address of MPW param table
13*
14*Exit:
15* No return value.
16*
17*Exceptions:
18*
19*******************************************************************************/
20
21 static void __cdecl Inherit (
22 void
23 )
24 {
25 MPWFILE *pFile;
26 int i;
27 pFile = _pMPWBlock->pFile;
28 if (pFile == NULL) {
29 return;
30 }
31 for (i = 0; i < 3; i++) {
32 switch ((pFile->pDevice)->name) {
33 case 'ECON':
34 _osfile[i] |= FDEV | FOPEN;
35 _osfhnd[i] = (int)pFile;
36 break;
37
38 case 'FSYS':
39 _osfile[i] |= FOPEN;
40 _osfhnd[i] = (*(pFile->ppFInfo))->ioRefNum;
41 break;
42 }
43 pFile++;
44 }
45}
46
47 #endif /* _M_MPPC */
48
49
50
51 static char * __cdecl _p2cstr_internal (
52 unsigned char * str
53 )
54 {
55 unsigned char *pchSrc;
56 unsigned char *pchDst;
57 int cch;
58
59 if ( str && *str ) {
60 pchDst = str;
61 pchSrc = str + 1;
62
63 for ( cch=*pchDst; cch; --cch ) {
64 *pchDst++ = *pchSrc++;
65 }
66
67 *pchDst = '\0';
68 }
69
70 return( str );
71}
72
73 #endif /* _WIN32 */
6. 如果是GUI程序,则要创建“内核对象”,请参考下面的MSDN中的STARTUPINFO结构体的说明
http://www.cnblogs.com/shanzy/articles/513455.html
7. 上面的crt0.c文件中涉及到MS针对不同的CPU厂商都能够跑MS的VC编译器的CPU假设,如下面MSDN文章所说------------当然,你也可以在代码中手写下面这些MS预定义宏,或者写MAKEFILE
Predefined Macros
The compiler recognizes six predefined ANSI C macros (see Table 1.1), and the Microsoft C++ implementation provides several more (see Table 1.2). These macros take no arguments and cannot be redefined. Their value (except for __LINE__ and __FILE__) must be constant throughout compilation. Some of the predefined macros listed below are defined with multiple values. Their values can be set by selecting the corresponding menu option in the Visual C++ development environment, or by using a command-line switch. See the tables below for more information.
Table 1.1 ANSI Predefined Macros
Macro | Description |
__DATE__ | The compilation date of the current source file. The date is a string literal of the form Mmm dd yyyy. The month name Mmm is the same as for dates generated by the library function asctime declared in TIME.H. |
__FILE__ | The name of the current source file. __FILE__ expands to a string surrounded by double quotation marks. |
__LINE__ | The line number in the current source file. The line number is a decimal integer constant. It can be altered with a #line directive. |
__STDC__ | Indicates full conformance with the ANSI C standard. Defined as the integer constant 1 only if the /Za compiler option is given and you are not compiling C++ code; otherwise is undefined. |
__TIME__ | The most recent compilation time of the current source file. The time is a string literal of the form hh:mm:ss. |
__TIMESTAMP__ | The date and time of the last modification of the current source file, expressed as a string literal in the form Ddd Mmm Date hh:mm:ss yyyy, where Ddd is the abbreviated day of the week and Date is an integer from 1 to 31. |
Table 1.2 Microsoft-Specific Predefined Macros
Macro | Description |
_CHAR_UNSIGNED | Default char type is unsigned. Defined when /J is specified. |
__cplusplus | Defined for C++ programs only. |
_CPPRTTI | Defined for code compiled with /GR (Enable Run-Time Type Information). |
_CPPUNWIND | Defined for code compiled with /GX (Enable Exception Handling). |
_DLL | Defined when /MD or /MDd (Multithread DLL) is specified. |
_M_ALPHA | Defined for DEC ALPHA platforms. It is defined as 1 by the ALPHA compiler, and it is not defined if another compiler is used. |
_M_IX86 | Defined for x86 processors. See Table 1.3 for more details. |
_M_MPPC | Defined for Power Macintosh platforms. Default is 601 (/QP601). See Table 1.4 for more details. |
_M_MRX000 | Defined for MIPS platforms. Default is 4000 (/QMR4000). See Table 1.5 for more details. |
_M_PPC | Defined for PowerPC platforms. Default is 604 (/QP604). See Table 1.6 for more details. |
_MFC_VER | Defines the MFC version. Defined as 0x0421 for Microsoft Foundation Class Library 4.21. Always defined. |
_MSC_EXTENSIONS | This macro is defined when compiling with the /Ze compiler option (the default). Its value, when defined, is 1. |
_MSC_VER | Defines the compiler version. Defined as 1200 for Microsoft Visual C++ 6.0. Always defined. |
_MT | Defined when /MD or /MDd (Multithreaded DLL) or /MT or /MTd(Multithreaded) is specified. |
_WIN32 | Defined for applications for Win32®. Always defined. |
As shown in following tables, the compiler generates a value for the preprocessor identifiers that reflect the processor option specified.
Option in Developer Studio | Command-Line Option | Resulting Value |
Blend | /GB | _M_IX86 = 500 (Default. Future compilers will emit a different value to reflect the dominant processor.) |
Pentium | /G5 | _M_IX86 = 500 |
Pentium Pro | /G6 | _M_IX86 = 600 |
80386 | /G3 | _M_IX86 = 300 |
80486 | /G4 | _M_IX86 = 400 |
Option in development environment | Command-Line Option | Resulting Value |
PowerPC 601 | /QP601 | _M_MPPC = 601 (Default) |
PowerPC 603 | /QP603 | _M_MPPC = 603 |
PowerPC 604 | /QP604 | _M_MPPC = 604 |
PowerPC 620 | /QP620 | _M_MPPC = 620 |
Table 1.5 Values for _M_MRX000
Option in Developer Studio | Command-Line Option | Resulting Value |
R4000 | /QMR4000 | _M_MRX000 = 4000 (Default) |
R4100 | /QMR4100 | _M_MRX000 = 4100 |
R4200 | /QMR4200 | _M_MRX000 = 4200 |
R4400 | /QMR4400 | _M_MRX000 = 4400 |
R4600 | /QMR4600 | _M_MRX000 = 4600 |
R10000 | /QMR10000 | _M_MRX000 = 10000 |
Option in Developer Studio | Command-Line Option | Resulting Value |
PowerPC 601 | /QP601 | _M_PPC = 601 |
PowerPC 603 | /QP603 | _M_PPC = 603 |
PowerPC 604 | /QP604 | _M_PPC = 604 (Default) |
PowerPC 620 | /QP620 | _M_PPC = 620 |
8. 任何C/C++编译器的构造,都是依托于ANSI C/ANSI C++标准的,但是,由于某些历史问题当ANSI标准影响了厂商的标准,或者厂商认为某些东西更利于开发的时候,厂商会在ANSI标准提供的编译器的基础上对CRT运行时库进行扩充,扩充的结果就是上面的情况
9. 厂商扩充了ANSI标准,就需要写出一个自己的编译器(MS 的VC编译器就是cl.exe),写这个cl.exe的过程要根据厂商扩充之后的各种标准表格,在写这个cl.exe的时候做出很多的选择分支(当然,MS这里用它认为重要的一些“自定义宏”来写它的cl.exe)
return用法之注意细节
返回类型规定了return后面所加的量的类型,如果返回类型声明为void,则不需要返回值
public static void Main()//程序入口只可以声明为void和int的返回
{
//不需要返回值就OK
}
public static void mm()
{
return;//有些时候,在void的方法中,你需要跳出它,可以直接用return而不能加任何量在后面
}
public static int cc()
{
return 321;//因为返回类型声明为int,所以返回一个整数
}
public static string msmsm()
{
return "asdfhasjghdg";//因为返回类型声明为string,所以返回一个字符串
}
—————————————————————————————————————————————————————————————————————————
return这个方法在函数中经常用到,而且用法也比较经典.
在下面我就return的用法要注意的地方说明下:
用法1:返回函数值:
例1:我现在编一个计算阶层的函数:
function jc(n){
var j=1;
for(var i=0;i<=n;i++){
j*=i;
}
return j;
}
alert(jc(5));
这里计算5!,输出为120;
这里return的功能为返回函数的值;
例2:我现在编另一个计算阶层的函数: function jc(n){
var j=1;
for(var i=0;;){
j*=++i;
if(i==n){return j;}
}
}
alert(jc(5));
这里计算5!,输出为120;
这里return的功能为跳出循环并且跳出函数,在返回函数值;
例3:另一个return例子
function cs(n){
if(n==1){retrun 1;}
if(n==2){return;}
else{}
}
说明:当参数为1时函数返回值为1并且跳出函数,
当参数为2时函数返回值为空并且跳出函数,
当函数为其他值时继续执行函数下面的语句,直到遇到下个return或则全部执行完语句在跳出函数
上面例子说明return可以返回一个函数的值,并且跳出这个函数;
上面的例子只说明了return的常规用途,下面我来说下它必须要注意的一个地方;
return可以返回很多数据类型,到目前为止,我还没有发现他不能返回什么,呵呵
包括在对dom进行操作的时候,比如,还是举例子说明;
例4:
<body>
<div id="kk"> aa </div>
</body>
<script>
function cs(ids){
return document.getElementById(ids).firstChild.nodeValue;
}
alert(cs("kk"));
//此时将返回div中的值即aa;
alert(document.getElementById(kk).firstChildnodeValue);
//虽然此时返回div中的值也为aa;
但是它们是不一样的,知道为什么吗???
呵呵,在举例:
document.getElementById(ids).firstChild.nodeValue="bb";
这时div中的值将从aa改成bb;
这个大家都知道,
当cs("kk")="bb";
你猜会不会也将div中的值从aa改成bb呢?
呵呵,这里,你就会明白return过来的对象是不能进行赋值操作的;
就是说cs("kk")="bb";这样进行赋值是会出错的,
这里就是我要说的return要注意的问题!!!
更多问题有待研究......
</script>