stdlib.h标准库头.doc_第1页
stdlib.h标准库头.doc_第2页
stdlib.h标准库头.doc_第3页
stdlib.h标准库头.doc_第4页
stdlib.h标准库头.doc_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

stdlib.h 标准库头文件一、 简介stdlib 头文件即standard library标准库头文件 stdlib 头文件里包含了C、C+语言的最常用的系统函数 该文件包含了的C语言标准库函数的定义 stdlib.h里面定义了五种类型、一些宏和通用工具函数。 类型例如size_t、wchar_t、div_t、ldiv_t和lldiv_t; 宏例如EXIT_FAILURE、EXIT_SUCCESS、RAND_MAX和MB_CUR_MAX等等; 常用的函数如malloc()、calloc()、realloc()、free()、system()、atoi()、atol()、rand()、srand()、exit()等等。二、 Stdlib.H具体内容/*stdlib.h - declarations/definitions for commonly used library functions* Copyright (c) 1985-1997, Microsoft Corporation. All rights reserved.*Purpose:* This include file contains the function declarations for commonly* used library functions which either dont fit somewhere else, or,* cannot be declared in the normal place for other reasons.* ANSI* Public*/#if _MSC_VER 1000#pragma once#endif /* _MSC_VER 1000 */#ifndef _INC_STDLIB#define _INC_STDLIB#if !defined (_WIN32) & !defined (_MAC)#error ERROR: Only Mac or Win32 targets supported!#endif /* !defined (_WIN32) & !defined (_MAC) */#ifndef _CRTBLD/* This version of the header files is NOT for user programs. * It is intended for use when building the C runtimes ONLY. * The version intended for public use will not have this message. */#error ERROR: Use of C runtime library internal header file.#endif /* _CRTBLD */#ifdef _MSC_VER/* * Currently, all MS C compilers for Win32 platforms default to 8 byte * alignment. */#pragma pack(push,8)#endif /* _MSC_VER */#ifdef _cplusplusextern C #endif /* _cplusplus */#ifndef _INTERNAL_IFSTRIP_#include #endif /* _INTERNAL_IFSTRIP_ */* Define _CRTIMP */#ifndef _CRTIMP#ifdef CRTDLL#define _CRTIMP _declspec(dllexport)#else /* CRTDLL */#ifdef _DLL#define _CRTIMP _declspec(dllimport)#else /* _DLL */#define _CRTIMP#endif /* _DLL */#endif /* CRTDLL */#endif /* _CRTIMP */* Define _cdecl for non-Microsoft compilers */#if (!defined (_MSC_VER) & !defined (_cdecl)#define _cdecl#endif /* (!defined (_MSC_VER) & !defined (_cdecl) */* Define _CRTAPI1 (for compatibility with the NT SDK) */#ifndef _CRTAPI1#if _MSC_VER = 800 & _M_IX86 = 300#define _CRTAPI1 _cdecl#else /* _MSC_VER = 800 & _M_IX86 = 300 */#define _CRTAPI1#endif /* _MSC_VER = 800 & _M_IX86 = 300 */#endif /* _CRTAPI1 */#ifndef _SIZE_T_DEFINEDtypedef unsigned int size_t;#define _SIZE_T_DEFINED#endif /* _SIZE_T_DEFINED */#ifndef _WCHAR_T_DEFINEDtypedef unsigned short wchar_t;#define _WCHAR_T_DEFINED#endif /* _WCHAR_T_DEFINED */* Define NULL pointer value */#ifndef NULL#ifdef _cplusplus#define NULL 0#else /* _cplusplus */#define NULL (void *)0)#endif /* _cplusplus */#endif /* NULL */* Definition of the argument values for the exit() function */#define EXIT_SUCCESS 0#define EXIT_FAILURE 1#ifndef _ONEXIT_T_DEFINEDtypedef int (_cdecl * _onexit_t)(void);#if !_STDC_/* Non-ANSI name for compatibility */#define onexit_t _onexit_t#endif /* !_STDC_ */#define _ONEXIT_T_DEFINED#endif /* _ONEXIT_T_DEFINED */* Data structure definitions for div and ldiv runtimes. */#ifndef _DIV_T_DEFINEDtypedef struct _div_t int quot; int rem; div_t;typedef struct _ldiv_t long quot; long rem; ldiv_t;#define _DIV_T_DEFINED#endif /* _DIV_T_DEFINED */* Maximum value that can be returned by the rand function. */#define RAND_MAX 0x7fff/* * Maximum number of bytes in multi-byte character in the current locale * (also defined in ctype.h). */#ifndef MB_CUR_MAX#ifndef _INTERNAL_IFSTRIP_#if defined (_DLL) & defined (_M_IX86)/* Retained for compatibility with VC+ 5.0 and earlier versions */_CRTIMP int * _cdecl _p_mb_cur_max(void);#endif /* defined (_DLL) & defined (_M_IX86) */#endif /* _INTERNAL_IFSTRIP_ */#define MB_CUR_MAX _mb_cur_max_CRTIMP extern int _mb_cur_max;#endif /* MB_CUR_MAX */* Minimum and maximum macros */#define _max(a,b) (a) (b) ? (a) : (b)#define _min(a,b) (a) = 1200_CRTIMP _declspec(noreturn) void _cdecl abort(void);_CRTIMP _declspec(noreturn) void _cdecl exit(int);#else /* _MSC_VER = 1200 */_CRTIMP void _cdecl abort(void);_CRTIMP void _cdecl exit(int);#endif /* _MSC_VER = 1200 */#if defined (_M_MRX000)_CRTIMP int _cdecl abs(int);#else /* defined (_M_MRX000) */ int _cdecl abs(int);#endif /* defined (_M_MRX000) */ int _cdecl atexit(void (_cdecl *)(void);_CRTIMP double _cdecl atof(const char *);_CRTIMP int _cdecl atoi(const char *);_CRTIMP long _cdecl atol(const char *);#ifdef _M_M68K_CRTIMP long double _cdecl _atold(const char *);#endif /* _M_M68K */_CRTIMP void * _cdecl bsearch(const void *, const void *, size_t, size_t, int (_cdecl *)(const void *, const void *);_CRTIMP void * _cdecl calloc(size_t, size_t);_CRTIMP div_t _cdecl div(int, int);_CRTIMP void _cdecl free(void *);_CRTIMP char * _cdecl getenv(const char *);_CRTIMP char * _cdecl _itoa(int, char *, int);#if _INTEGRAL_MAX_BITS = 64 _CRTIMP char * _cdecl _i64toa(_int64, char *, int);_CRTIMP char * _cdecl _ui64toa(unsigned _int64, char *, int);_CRTIMP _int64 _cdecl _atoi64(const char *);#endif /* _INTEGRAL_MAX_BITS = 64 */#if defined (_M_MRX000)_CRTIMP long _cdecl labs(long);#else /* defined (_M_MRX000) */ long _cdecl labs(long);#endif /* defined (_M_MRX000) */_CRTIMP ldiv_t _cdecl ldiv(long, long);_CRTIMP char * _cdecl _ltoa(long, char *, int);_CRTIMP void * _cdecl malloc(size_t);_CRTIMP int _cdecl mblen(const char *, size_t);_CRTIMP size_t _cdecl _mbstrlen(const char *s);_CRTIMP int _cdecl mbtowc(wchar_t *, const char *, size_t);_CRTIMP size_t _cdecl mbstowcs(wchar_t *, const char *, size_t);_CRTIMP void _cdecl qsort(void *, size_t, size_t, int (_cdecl *) (const void *, const void *);_CRTIMP int _cdecl rand(void);_CRTIMP void * _cdecl realloc(void *, size_t);_CRTIMP int _cdecl _set_error_mode(int);_CRTIMP void _cdecl srand(unsigned int);_CRTIMP double _cdecl strtod(const char *, char *);_CRTIMP long _cdecl strtol(const char *, char *, int);#ifdef _M_M68K_CRTIMP long double _cdecl _strtold(const char *, char *);#endif /* _M_M68K */_CRTIMP unsigned long _cdecl strtoul(const char *, char *, int);#ifndef _MAC_CRTIMP int _cdecl system(const char *);#endif /* _MAC */_CRTIMP char * _cdecl _ultoa(unsigned long, char *, int);_CRTIMP int _cdecl wctomb(char *, wchar_t);_CRTIMP size_t _cdecl wcstombs(char *, const wchar_t *, size_t);#ifndef _MAC#ifndef _WSTDLIB_DEFINED/* wide function prototypes, also declared in wchar.h */_CRTIMP wchar_t * _cdecl _itow (int, wchar_t *, int);_CRTIMP wchar_t * _cdecl _ltow (long, wchar_t *, int);_CRTIMP wchar_t * _cdecl _ultow (unsigned long, wchar_t *, int);_CRTIMP double _cdecl wcstod(const wchar_t *, wchar_t *);_CRTIMP long _cdecl wcstol(const wchar_t *, wchar_t *, int);_CRTIMP unsigned long _cdecl wcstoul(const wchar_t *, wchar_t *, int);_CRTIMP wchar_t * _cdecl _wgetenv(const wchar_t *);_CRTIMP int _cdecl _wsystem(const wchar_t *);_CRTIMP int _cdecl _wtoi(const wchar_t *);_CRTIMP long _cdecl _wtol(const wchar_t *);#if _INTEGRAL_MAX_BITS = 64 _CRTIMP wchar_t * _cdecl _i64tow(_int64, wchar_t *, int);_CRTIMP wchar_t * _cdecl _ui64tow(unsigned _int64, wchar_t *, int);_CRTIMP _int64 _cdecl _wtoi64(const wchar_t *);#endif /* _INTEGRAL_MAX_BITS = 64 */#define _WSTDLIB_DEFINED#endif /* _WSTDLIB_DEFINED */#endif /* _MAC */_CRTIMP char * _cdecl _ecvt(double, int, int *, int *);#if _MSC_VER = 1200_CRTIMP _declspec(noreturn) void _cdecl _exit(int);#else /* _MSC_VER = 1200 */_CRTIMP void _cdecl _exit(int);#endif /* _MSC_VER = 1200 */_CRTIMP char * _cdecl _fcvt(double, int, int *, int *);_CRTIMP char * _cdecl _fullpath(char *, const char *, size_t);_CRTIMP char * _cdecl _gcvt(double, int, char *); unsigned long _cdecl _lrotl(unsigned long, int); unsigned long _cdecl _lrotr(unsigned long, int);#ifndef _MAC_CRTIMP void _cdecl _makepath(char *, const char *, const char *, const char *, const char *);#endif /* _MAC */ _onexit_t _cdecl _onexit(_onexit_t);_CRTIMP void _cdecl perror(const char *);_CRTIMP int _cdecl _putenv(const char *); unsigned int _cdecl _rotl(unsigned int, int); unsigned int _cdecl _rotr(unsigned int, int);_CRTIMP void _cdecl _searchenv(const char *, const char *, char *);#ifndef _MAC_CRTIMP void _cdecl _splitpath(const char *, char *, char *, char *, char *);#endif /* _MAC */_CRTIMP void _cdecl _swab(char *, char *, int);#ifndef _MAC#ifndef _WSTDLIBP_DEFINED/* wide function prototypes, also declared in wchar.h */_CRTIMP wchar_t * _cdecl _wfullpath(wchar_t *, const wchar_t *, size_t);_CRTIMP void _cdecl _wmakepath(wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *, const wchar_t *);_CRTIMP void _cdecl _wperror(const wchar_t *);_CRTIMP int _cdecl _wputenv(const wchar_t *);_CRTIMP void _cdecl _wsearchenv(const wchar_t *, const wchar_t *, wchar_t *);_CRTIMP void _cdecl _wsplitpath(const wchar_t *, wchar_t *, wchar_t *, wchar_t *, wchar_t *);#define _WSTDLIBP_DEFINED#endif /* _WSTDLIBP_DEFINED */#endif /* _MAC */* - The following functions are OBSOLETE - */* The Win32 API SetErrorMode, Beep and Sleep should be used instead. */#ifndef _MAC_CRTIMP void _cdecl _seterrormode(int);_CRTIMP void _cdecl _beep(unsigned, unsigned);_CRTIMP void _cdecl _sleep(unsigned long);#endif /* _MAC */* - The preceding functions are OBSOLETE - */#if !_STDC_/* - The declarations below should not be in stdlib.h - */* - and will be removed in a future release. Include - */* - ctype.h to obtain these declarations. - */#ifndef tolower_CRTIMP int _cdecl tolower(int);#endif /* tolower */#ifndef toupper_CRTIMP int _cdecl toupper(int);#endif /* toupper */* - The declarations above will be removed. - */#endif /* !_STDC_ */#ifdef _MTchar * _cdecl _getenv_lk(const char *); /* _MTHREAD_ONLY */#ifndef _MACwchar_t * _cdecl _wgetenv_lk(const wchar_t *); /* _MTHREAD_ONLY */#endif /* _MAC */int _cdecl _putenv_lk(const char *); /* _MTHREAD_ONLY */#ifndef _MACint _cdecl _wputenv_lk(const wchar_t *); /* _MTHREAD_ONLY */#endif /* _MAC */int _cdecl _mblen_lk(const char *, size_t); /* _MTHREAD_ONLY */int _cdecl _mbtowc_lk(wchar_t*,const char*,size_t); /* _MTHREAD_ONLY */size_t _cdecl _mbstowcs_lk(wchar_t*,const char*,size_t); /* _MTHREAD_ONLY */int _cdecl _wctomb_lk(char*,wchar_t); /* _MTHREAD_ONLY */size_t _cdecl _wcstombs_lk(char*,const wchar_t*,size_t); /* _MTHREAD_ONLY */#else /* _MT */#define _getenv_lk(envvar) getenv(envvar) /* _MTHREAD_ONLY */#ifndef _MAC#define _wgetenv_lk(envvar) _wgetenv(envvar) /* _MTHREAD_ONLY */#endif /* _MAC */#define _putenv_lk(envvar) _putenv(envvar) /* _MTHREAD_ONLY */#ifndef _MAC#define _wputenv_lk(envvar) _wputenv(envvar) /* _MTHREAD_ONLY */#endif /* _MAC */#define _mblen_lk(s,n) mblen(s,n) /* _MTHREAD_ONLY */#define _mbtowc_lk(pwc,s,n) mbtowc(pwc,s,n) /* _MTHREAD_ONLY */#define _mbstowcs_lk(pwcs,s,n) mbstowcs(pwcs,s,n) /* _MTHREAD_ONLY */#define _wctomb_lk(s,wchar) wctomb(s,wchar) /* _MTHREAD_ONLY */#define _wcstombs_lk(s,pwcs,n) wcstombs(s,pwcs,n) /* _MTHREAD_ONLY */#endif /* _MT */#if !_STDC_/* Non-ANSI names for compatibility */#ifndef _cplusplus#define max(a,b) (a) (b) ? (a) : (b)#define min(a,b) (a) (b) ? (a) : (b)#endif /* _cplusplus */#define sys_errlist _sys_errlist#define sys_nerr _sys_nerr#define environ _environ_CRTIMP char * _cdecl ecvt(double, int, int *, int *);_CRTIMP char * _cdecl fcvt(double, int, int *, int *);_CRTIMP char * _cdecl gcvt(double, int, char *);_CRTIMP char * _cdecl itoa(int, char *, int);_CRTIMP char * _cdecl ltoa(long, char *, int); onexit_t _cdecl onexit(onexit_t);_CRTIMP int _cdecl putenv(const char *);_CRTIMP void _cdecl swab(char *, char *, int);_CRTIMP char * _cdecl ultoa(unsigned long, char *, int);#endif /* !_STDC_ */#ifdef _cplusplus#endif /* _cplusplus */#ifdef _MSC_VER#pragma pack(pop)#endif /* _MSC_VER */#endif /* _INC_STDLIB */三、 stdlib.h用法1函数名称: calloc 函数原型: void * calloc(unsigned n,unsign size); 函数功能: 分配n个数据项的内存连续空间,每个数据项的大小为size 函数返回: 分配内存单元的起始地址,如果不成功,返回0 2函数名称: free 函数原型: void free(void* p); 函数功能: 释放p所指的内存区 函数返回: 参数说明: p-被释放的指针 3函数名称: malloc 函数原

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论