我们先来看看古老的TC2中stdlib.h文件的内容,如下:

TC2下的stdlib.h
1
/**//* stdlib.h
2
3
Definitions for common types, variables, and functions.
4
5
Copyright (c) Borland International 1987,1988
6
All Rights Reserved.
7
*/
8
#if __STDC__
9
#define _Cdecl
10
#else
11
#define _Cdecl cdecl
12
#endif
13
14
#if !defined(__STDLIB)
15
#define __STDLIB
16
17
#ifndef _SIZE_T
18
#define _SIZE_T
19
typedef unsigned size_t;
20
#endif
21
22
#ifndef _DIV_T
23
#define _DIV_T
24
typedef struct
{
25
int quot;
26
int rem;
27
} div_t;
28
#endif
29
30
#ifndef _LDIV_T
31
#define _LDIV_T
32
typedef struct
{
33
long quot;
34
long rem;
35
} ldiv_t;
36
#endif
37
38
#define EXIT_SUCCESS 0
39
#define EXIT_FAILURE 1
40
41
/**//* Maximum value returned by "rand" function
42
*/
43
#define RAND_MAX 0x7FFF
44
45
typedef void _Cdecl (* atexit_t)(void);
46
47
void _Cdecl abort (void);
48
int _Cdecl abs (int x);
49
int _Cdecl atexit (atexit_t func);
50
double _Cdecl atof (const char *s);
51
int _Cdecl atoi (const char *s);
52
long _Cdecl atol (const char *s);
53
void *_Cdecl bsearch(const void *key, const void *base,
54
size_t nelem, size_t width,
55
int _Cdecl (*fcmp)(/**//* const void *, const void * */));
56
void *_Cdecl calloc (size_t nitems, size_t size);
57
div_t _Cdecl div (int numer, int denom);
58
void _Cdecl exit (int status);
59
void _Cdecl free (void *block);
60
char *_Cdecl getenv (const char *name);
61
long _Cdecl labs (long x);
62
ldiv_t _Cdecl ldiv (long numer, long denom);
63
void *_Cdecl malloc (size_t size);
64
void _Cdecl qsort (void *base, size_t nelem, size_t width,
65
int _Cdecl (*fcmp)(/**//* const void *, const void * */));
66
int _Cdecl rand (void);
67
void *_Cdecl realloc(void *block, size_t size);
68
void _Cdecl srand (unsigned seed);
69
double _Cdecl strtod (const char *s, char **endptr);
70
long _Cdecl strtol (const char *s, char **endptr, int radix);
71
unsigned long _Cdecl strtoul (const char *s, char **endptr, int radix);
72
int _Cdecl system (const char *command);
73
74
#if !__STDC__
75
76
#ifndef NULL
77
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
78
#define NULL 0
79
#else
80
#define NULL 0L
81
#endif
82
#endif
83
84
/**//* Variables */
85
extern int _Cdecl _doserrno;
86
extern char **_Cdecl environ;
87
extern int _Cdecl errno;
88
extern int _Cdecl _fmode;
89
extern unsigned char _Cdecl _osmajor;
90
extern unsigned char _Cdecl _osminor;
91
extern unsigned _Cdecl _psp;
92
extern char *_Cdecl sys_errlist[];
93
extern int _Cdecl sys_nerr;
94
extern unsigned int _Cdecl _version;
95
96
int _Cdecl __abs__(int x); /**//* This is an in-line function */
97
#define abs(x) __abs__(x)
98
#define atoi(s) ((int) atol (s))
99
100
#define max(a,b) (((a) > (b)) ? (a) : (b))
101
#define min(a,b) (((a) < (b)) ? (a) : (b))
102
103
#define random(num) (rand() % (num))
104
#define randomize() srand((unsigned)time(NULL))
105
106
char *_Cdecl ecvt (double value, int ndig, int *dec, int *sign);
107
void _Cdecl _exit (int status);
108
char *_Cdecl fcvt (double value, int ndig, int *dec, int *sign);
109
char *_Cdecl gcvt (double value, int ndec, char *buf);
110
char *_Cdecl itoa (int value, char *string, int radix);
111
void *_Cdecl lfind (const void *key, const void *base,
112
size_t *num, size_t width,
113
int _Cdecl (*fcmp)(/**//* const void *, const void * */));
114
115
unsigned long _Cdecl _lrotl(unsigned long val, int count);
116
unsigned long _Cdecl _lrotr(unsigned long val, int count);
117
118
void *_Cdecl lsearch (const void *key, void *base,
119
size_t *num, size_t width,
120
int _Cdecl (*fcmp)(/**//* const void *, const void * */));
121
char *_Cdecl ltoa (long value, char *string, int radix);
122
int _Cdecl putenv (const char *name);
123
124
unsigned _Cdecl _rotl (unsigned value, int count);
125
unsigned _Cdecl _rotr (unsigned value, int count);
126
127
void _Cdecl swab (char *from, char *to, int nbytes);
128
char *_Cdecl ultoa (unsigned long value, char *string, int radix);
129
#endif
130
131
#endif
132
我们再来看看MS的VC编译器中的stdlib.h文件的内容,如下:

MS的VC编译器中附带的stdlib.h
1
/**//***
2
*stdlib.h - declarations/definitions for commonly used library functions
3
*
4
* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.
5
*
6
*Purpose:
7
* This include file contains the function declarations for commonly
8
* used library functions which either don't fit somewhere else, or,
9
* cannot be declared in the normal place for other reasons.
10
* [ANSI]
11
*
12
* [Public]
13
*
14
****/
15
16
#if _MSC_VER > 1000
17
#pragma once
18
#endif
19
20
#ifndef _INC_STDLIB
21
#define _INC_STDLIB
22
23
#if !defined(_WIN32) && !defined(_MAC)
24
#error ERROR: Only Mac or Win32 targets supported!
25
#endif
26
27
28
#ifdef _MSC_VER
29
/**//*
30
* Currently, all MS C compilers for Win32 platforms default to 8 byte
31
* alignment.
32
*/
33
#pragma pack(push,8)
34
#endif /* _MSC_VER */
35
36
#ifdef __cplusplus
37
extern "C"
{
38
#endif
39
40
41
42
/**//* Define _CRTIMP */
43
44
#ifndef _CRTIMP
45
#ifdef _DLL
46
#define _CRTIMP __declspec(dllimport)
47
#else /* ndef _DLL */
48
#define _CRTIMP
49
#endif /* _DLL */
50
#endif /* _CRTIMP */
51
52
53
/**//* Define __cdecl for non-Microsoft compilers */
54
55
#if ( !defined(_MSC_VER) && !defined(__cdecl) )
56
#define __cdecl
57
#endif
58
59
/**//* Define _CRTAPI1 (for compatibility with the NT SDK) */
60
61
#ifndef _CRTAPI1
62
#if _MSC_VER >= 800 && _M_IX86 >= 300
63
#define _CRTAPI1 __cdecl
64
#else
65
#define _CRTAPI1
66
#endif
67
#endif
68
69
70
#ifndef _SIZE_T_DEFINED
71
typedef unsigned int size_t;
72
#define _SIZE_T_DEFINED
73
#endif
74
75
76
#ifndef _WCHAR_T_DEFINED
77
typedef unsigned short wchar_t;
78
#define _WCHAR_T_DEFINED
79
#endif
80
81
82
/**//* Define NULL pointer value */
83
84
#ifndef NULL
85
#ifdef __cplusplus
86
#define NULL 0
87
#else
88
#define NULL ((void *)0)
89
#endif
90
#endif
91
92
93
/**//* Definition of the argument values for the exit() function */
94
95
#define EXIT_SUCCESS 0
96
#define EXIT_FAILURE 1
97
98
99
#ifndef _ONEXIT_T_DEFINED
100
typedef int (__cdecl * _onexit_t)(void);
101
#if !__STDC__
102
/**//* Non-ANSI name for compatibility */
103
#define onexit_t _onexit_t
104
#endif
105
#define _ONEXIT_T_DEFINED
106
#endif
107
108
109
/**//* Data structure definitions for div and ldiv runtimes. */
110
111
#ifndef _DIV_T_DEFINED
112
113
typedef struct _div_t
{
114
int quot;
115
int rem;
116
} div_t;
117
118
typedef struct _ldiv_t
{
119
long quot;
120
long rem;
121
} ldiv_t;
122
123
#define _DIV_T_DEFINED
124
#endif
125
126
127
/**//* Maximum value that can be returned by the rand function. */
128
129
#define RAND_MAX 0x7fff
130
131
/**//*
132
* Maximum number of bytes in multi-byte character in the current locale
133
* (also defined in ctype.h).
134
*/
135
#ifndef MB_CUR_MAX
136
#define MB_CUR_MAX __mb_cur_max
137
_CRTIMP extern int __mb_cur_max;
138
#endif /* MB_CUR_MAX */
139
140
141
/**//* Minimum and maximum macros */
142
143
#define __max(a,b) (((a) > (b)) ? (a) : (b))
144
#define __min(a,b) (((a) < (b)) ? (a) : (b))
145
146
/**//*
147
* Sizes for buffers used by the _makepath() and _splitpath() functions.
148
* note that the sizes include space for 0-terminator
149
*/
150
#ifndef _MAC
151
#define _MAX_PATH 260 /* max. length of full pathname */
152
#define _MAX_DRIVE 3 /* max. length of drive component */
153
#define _MAX_DIR 256 /* max. length of path component */
154
#define _MAX_FNAME 256 /* max. length of file name component */
155
#define _MAX_EXT 256 /* max. length of extension component */
156
#else /* def _MAC */
157
#define _MAX_PATH 256 /* max. length of full pathname */
158
#define _MAX_DIR 32 /* max. length of path component */
159
#define _MAX_FNAME 64 /* max. length of file name component */
160
#endif /* _MAC */
161
162
/**//*
163
* Argument values for _set_error_mode().
164
*/
165
#define _OUT_TO_DEFAULT 0
166
#define _OUT_TO_STDERR 1
167
#define _OUT_TO_MSGBOX 2
168
#define _REPORT_ERRMODE 3
169
170
171
/**//* External variable declarations */
172
173
#if (defined(_MT) || defined(_DLL)) && !defined(_MAC)
174
_CRTIMP int * __cdecl _errno(void);
175
_CRTIMP unsigned long * __cdecl __doserrno(void);
176
#define errno (*_errno())
177
#define _doserrno (*__doserrno())
178
#else /* ndef _MT && ndef _DLL */
179
_CRTIMP extern int errno; /**//* XENIX style error number */
180
_CRTIMP extern unsigned long _doserrno; /**//* OS system error value */
181
#endif /* _MT || _DLL */
182
183
184
#ifdef _MAC
185
_CRTIMP extern int _macerrno; /**//* OS system error value */
186
#endif
187
188
189
_CRTIMP extern char * _sys_errlist[]; /**//* perror error message table */
190
_CRTIMP extern int _sys_nerr; /**//* # of entries in sys_errlist table */
191
192
193
#if defined(_DLL) && defined(_M_IX86)
194
195
#define __argc (*__p___argc()) /* count of cmd line args */
196
#define __argv (*__p___argv()) /* pointer to table of cmd line args */
197
#define __wargv (*__p___wargv()) /* pointer to table of wide cmd line args */
198
#define _environ (*__p__environ()) /* pointer to environment table */
199
#ifdef _POSIX_
200
extern char ** environ; /**//* pointer to environment table */
201
#else
202
#ifndef _MAC
203
#define _wenviron (*__p__wenviron()) /* pointer to wide environment table */
204
#endif /* ndef _MAC */
205
#endif /* _POSIX_ */
206
#define _pgmptr (*__p__pgmptr()) /* points to the module (EXE) name */
207
#ifndef _MAC
208
#define _wpgmptr (*__p__wpgmptr()) /* points to the module (EXE) wide name */
209
#endif /* ndef _MAC */
210
211
_CRTIMP int * __cdecl __p___argc(void);
212
_CRTIMP char *** __cdecl __p___argv(void);
213
_CRTIMP wchar_t *** __cdecl __p___wargv(void);
214
_CRTIMP char *** __cdecl __p__environ(void);
215
_CRTIMP wchar_t *** __cdecl __p__wenviron(void);
216
_CRTIMP char ** __cdecl __p__pgmptr(void);
217
_CRTIMP wchar_t ** __cdecl __p__wpgmptr(void);
218
219
220
#else
221
222
_CRTIMP extern int __argc; /**//* count of cmd line args */
223
_CRTIMP extern char ** __argv; /**//* pointer to table of cmd line args */
224
#ifndef _MAC
225
_CRTIMP extern wchar_t ** __wargv; /**//* pointer to table of wide cmd line args */
226
#endif /* ndef _MAC */
227
228
#ifdef _POSIX_
229
extern char ** environ; /**//* pointer to environment table */
230
#else
231
_CRTIMP extern char ** _environ; /**//* pointer to environment table */
232
#ifndef _MAC
233
_CRTIMP extern wchar_t ** _wenviron; /**//* pointer to wide environment table */
234
#endif /* ndef _MAC */
235
#endif /* _POSIX_ */
236
237
_CRTIMP extern char * _pgmptr; /**//* points to the module (EXE) name */
238
#ifndef _MAC
239
_CRTIMP extern wchar_t * _wpgmptr; /**//* points to the module (EXE) wide name */
240
#endif /* ndef _MAC */
241
242
#endif
243
244
245
_CRTIMP extern int _fmode; /**//* default file translation mode */
246
_CRTIMP extern int _fileinfo; /**//* open file info mode (for spawn) */
247
248
249
/**//* Windows major/minor and O.S. version numbers */
250
251
_CRTIMP extern unsigned int _osver;
252
_CRTIMP extern unsigned int _winver;
253
_CRTIMP extern unsigned int _winmajor;
254
_CRTIMP extern unsigned int _winminor;
255
256
257
/**//* function prototypes */
258
259
#if _MSC_VER >= 1200
260
_CRTIMP __declspec(noreturn) void __cdecl abort(void);
261
_CRTIMP __declspec(noreturn) void __cdecl exit(int);
262
#else
263
_CRTIMP void __cdecl abort(void);
264
_CRTIMP void __cdecl exit(int);
265
#endif
266
267
#if defined(_M_MRX000)
268
_CRTIMP int __cdecl abs(int);
269
#else
270
int __cdecl abs(int);
271
#endif
272
int __cdecl atexit(void (__cdecl *)(void));
273
_CRTIMP double __cdecl atof(const char *);
274
_CRTIMP int __cdecl atoi(const char *);
275
_CRTIMP long __cdecl atol(const char *);
276
#ifdef _M_M68K
277
_CRTIMP long double __cdecl _atold(const char *);
278
#endif
279
_CRTIMP void * __cdecl bsearch(const void *, const void *, size_t, size_t,
280
int (__cdecl *)(const void *, const void *));
281
_CRTIMP void * __cdecl calloc(size_t, size_t);
282
_CRTIMP div_t __cdecl div(int, int);
283
_CRTIMP void __cdecl free(void *);
284
_CRTIMP char * __cdecl getenv(const char *);
285
_CRTIMP char * __cdecl _itoa(int, char *, int);
286
#if _INTEGRAL_MAX_BITS >= 64
287
_CRTIMP char * __cdecl _i64toa(__int64, char *, int);
288
_CRTIMP char * __cdecl _ui64toa(unsigned __int64, char *, int);
289
_CRTIMP __int64 __cdecl _atoi64(const char *);
290
#endif
291
#if defined(_M_MRX000)
292
_CRTIMP long __cdecl labs(long);
293
#else
294
long __cdecl labs(long);
295
#endif
296
_CRTIMP ldiv_t __cdecl ldiv(long, long);
297
_CRTIMP char * __cdecl _ltoa(long, char *, int);
298
_CRTIMP void * __cdecl malloc(size_t);
299
_CRTIMP int __cdecl mblen(const char *, size_t);
300
_CRTIMP size_t __cdecl _mbstrlen(const char *s);
301
_CRTIMP int __cdecl mbtowc(wchar_t *, const char *, size_t);
302
_CRTIMP size_t __cdecl mbstowcs(wchar_t *, const char *, size_t);
303
_CRTIMP void __cdecl qsort(void *, size_t, size_t, int (__cdecl *)
304
(const void *, const void *));
305
_CRTIMP int __cdecl rand(void);
306
_CRTIMP void * __cdecl realloc(void *, size_t);
307
_CRTIMP int __cdecl _set_error_mode(int);
308
_CRTIMP void __cdecl srand(unsigned int);
309
_CRTIMP double __cdecl strtod(const char *, char **);
310
_CRTIMP long __cdecl strtol(const char *, char **, int);
311
#ifdef _M_M68K
312
_CRTIMP long double __cdecl _strtold(const char *, char **);
313
#endif
314
_CRTIMP unsigned long __cdecl strtoul(const char *, char **, int);
315
#ifndef _MAC
316
_CRTIMP int __cdecl system(const char *);
317
#endif
318
_CRTIMP char * __cdecl _ultoa(unsigned long, char *, int);
319
_CRTIMP int __cdecl wctomb(char *, wchar_t);
320
_CRTIMP size_t __cdecl wcstombs(char *, const wchar_t *, size_t);
321
322
323
#ifndef _MAC
324
#ifndef _WSTDLIB_DEFINED
325
326
/**//* wide function prototypes, also declared in wchar.h */
327
328
_CRTIMP wchar_t * __cdecl _itow (int, wchar_t *, int);
329
_CRTIMP wchar_t * __cdecl _ltow (long, wchar_t *, int);
330
_CRTIMP wchar_t * __cdecl _ultow (unsigned long, wchar_t *, int);
331
_CRTIMP double __cdecl wcstod(const wchar_t *, wchar_t **);
332
_CRTIMP long __cdecl wcstol(const wchar_t *, wchar_t **, int);
333
_CRTIMP unsigned long __cdecl wcstoul(const wchar_t *, wchar_t **, int);
334
_CRTIMP wchar_t * __cdecl _wgetenv(const wchar_t *);
335
_CRTIMP int __cdecl _wsystem(const wchar_t *);
336
_CRTIMP int __cdecl _wtoi(const wchar_t *);
337
_CRTIMP long __cdecl _wtol(const wchar_t *);
338
#if _INTEGRAL_MAX_BITS >= 64
339
_CRTIMP wchar_t * __cdecl _i64tow(__int64, wchar_t *, int);
340
_CRTIMP wchar_t * __cdecl _ui64tow(unsigned __int64, wchar_t *, int);
341
_CRTIMP __int64 __cdecl _wtoi64(const wchar_t *);
342
#endif
343
344
#define _WSTDLIB_DEFINED
345
#endif
346
#endif /* ndef _MAC */
347
348
349
#ifndef _POSIX_
350
351
_CRTIMP char * __cdecl _ecvt(double, int, int *, int *);
352
#if _MSC_VER >= 1200
353
_CRTIMP __declspec(noreturn) void __cdecl _exit(int);
354
#else
355
_CRTIMP void __cdecl _exit(int);
356
#endif
357
_CRTIMP char * __cdecl _fcvt(double, int, int *, int *);
358
_CRTIMP char * __cdecl _fullpath(char *, const char *, size_t);
359
_CRTIMP char * __cdecl _gcvt(double, int, char *);
360
unsigned long __cdecl _lrotl(unsigned long, int);
361
unsigned long __cdecl _lrotr(unsigned long, int);
362
#ifndef _MAC
363
_CRTIMP void __cdecl _makepath(char *, const char *, const char *, const char *,
364
const char *);
365
#endif
366
_onexit_t __cdecl _onexit(_onexit_t);
367
_CRTIMP void __cdecl perror(const char *);
368
_CRTIMP int __cdecl _putenv(const char *);
369
unsigned int __cdecl _rotl(unsigned int, int);
370
unsigned int __cdecl _rotr(unsigned int, int);
371
_CRTIMP void __cdecl _searchenv(const char *, const char *, char *);
372
#ifndef _MAC
373
_CRTIMP void __cdecl _splitpath(const char *, char *, char *, char *, char *);
374
#endif
375
_CRTIMP void __cdecl _swab(char *, char *, int);
376
377
#ifndef _MAC
378
#ifndef _WSTDLIBP_DEFINED
379
380
/**//* wide function prototypes, also declared in wchar.h */
381
382
_CRTIMP wchar_t * __cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);
383
_CRTIMP void __cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *,
384
const wchar_t *);
385
_CRTIMP void __cdecl _wperror(const wchar_t *);
386
_CRTIMP int __cdecl _wputenv(const wchar_t *);
387
_CRTIMP void __cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);
388
_CRTIMP void __cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);
389
390
#define _WSTDLIBP_DEFINED
391
#endif
392
#endif /* ndef _MAC */
393
394
/**//* --------- The following functions are OBSOLETE --------- */
395
/**//* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */
396
#ifndef _MAC
397
_CRTIMP void __cdecl _seterrormode(int);
398
_CRTIMP void __cdecl _beep(unsigned, unsigned);
399
_CRTIMP void __cdecl _sleep(unsigned long);
400
#endif /* ndef _MAC */
401
/**//* --------- The preceding functions are OBSOLETE --------- */
402
403
#endif /* _POSIX_ */
404
405
406
#if !__STDC__
407
/**//* --------- The declarations below should not be in stdlib.h --------- */
408
/**//* --------- and will be removed in a future release. Include --------- */
409
/**//* --------- ctype.h to obtain these declarations. --------- */
410
#ifndef tolower /**//* tolower has been undefined - use function */
411
_CRTIMP int __cdecl tolower(int);
412
#endif /* tolower */
413
#ifndef toupper /**//* toupper has been undefined - use function */
414
_CRTIMP int __cdecl toupper(int);
415
#endif /* toupper */
416
/**//* --------- The declarations above will be removed. --------- */
417
#endif
418
419
420
#if !__STDC__
421
422
#ifndef _POSIX_
423
424
/**//* Non-ANSI names for compatibility */
425
426
#ifndef __cplusplus
427
#define max(a,b) (((a) > (b)) ? (a) : (b))
428
#define min(a,b) (((a) < (b)) ? (a) : (b))
429
#endif
430
431
#define sys_errlist _sys_errlist
432
#define sys_nerr _sys_nerr
433
#define environ _environ
434
435
_CRTIMP char * __cdecl ecvt(double, int, int *, int *);
436
_CRTIMP char * __cdecl fcvt(double, int, int *, int *);
437
_CRTIMP char * __cdecl gcvt(double, int, char *);
438
_CRTIMP char * __cdecl itoa(int, char *, int);
439
_CRTIMP char * __cdecl ltoa(long, char *, int);
440
onexit_t __cdecl onexit(onexit_t);
441
_CRTIMP int __cdecl putenv(const char *);
442
_CRTIMP void __cdecl swab(char *, char *, int);
443
_CRTIMP char * __cdecl ultoa(unsigned long, char *, int);
444
445
#endif /* _POSIX_ */
446
447
#endif /* __STDC__ */
448
449
#ifdef __cplusplus
450
}
451
452
#endif
453
454
#ifdef _MSC_VER
455
#pragma pack(pop)
456
#endif /* _MSC_VER */
457
458
#endif /* _INC_STDLIB */
459
==================================================
我们首先关注的内容是下面的代码:(第42------50行)
1
/**//* Define _CRTIMP */
2
3
#ifndef _CRTIMP
4
#ifdef _DLL
5
#define _CRTIMP __declspec(dllimport)
6
#else /* ndef _DLL */
7
#define _CRTIMP
8
#endif /* _DLL */
9
#endif /* _CRTIMP */