首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C 語言頭文件全景圖:Turbo C 經典庫與標準庫函數原型聲明速查

     編輯:關於C語言

頭文件核心作用

C 庫文件分兩類:

  1. 頭文件 (.h):常量定義、類型定義、宏定義、函數原型聲明、編譯選項設置。**調用庫函數前必須包含對應頭文件**,否則編譯器不知函數簽名,產生隱式聲明警告/錯誤。
  2. 函數庫 (.lib/.a/.so/.dll):函數目標代碼,鏈接階段解析符號地址。

Turbo C 經典頭文件完整清單 (31項)

頭文件核心功能與典型函數/宏
ALLOC.H內存管理:malloc, free, calloc, realloc, farcalloc, farmalloc (大內存模型)
ASSERT.H斷言宏:assert(expr),調試時檢查前置條件
BIOS.HIBM PC ROM BIOS 中斷調用:bioskey, biosdisk, biosprint
CONIO.HDOS 控制台 I/O:**非標準**,getch, kbhit, clrscr, gotoxy, textcolor, cprintf
CTYPE.H字符分類/轉換:isalpha, isdigit, isspace, toupper, tolower, toascii
DIR.H目錄/路徑操作:mkdir, rmdir, chdir, getcwd, findfirst, findnext
DOS.HDOS 系統調用/中斷:int86, intdos, gettime, setdate, REGS, SREGS
ERRNO.H錯誤碼助記符:EDOM, ERANGE, ENOMEM, EINVAL 等
FCNTL.H文件控制選項:O_RDONLY, O_WRONLY, O_CREAT, O_BINARY (open 參數)
FLOAT.H浮點特性常量:FLT_MAX, DBL_EPSILON, FLT_DIG
GRAPHICS.HBGI 圖形庫:initgraph, closegraph, line, circle, setcolor, floodfill
IO.H低級 I/O:open, close, read, write, lseek, tell, eof
LIMITS.H整數類型極限:INT_MAX, CHAR_BIT, LONG_MIN, UINT_MAX
MATH.H數學函數:sin, cos, tan, sqrt, pow, log, exp, fabs, ceil, floor, HUGE_VAL
MEM.H內存操作 (多與 STRING.H 重疊):memcpy, memset, memcmp, memchr, movmem
PROCESS.H進程控制:spawn..., exec..., _exit, getpid
SETJMP.H非局部跳轉:setjmp, longjmp, jmp_buf
SHARE.H文件共享模式:SH_COMPAT, SH_DENYRW, SH_DENYWR, SH_DENYRD, SH_DENYNO
SIGNAL.H信號處理:signal, raise, SIG_DFL, SIG_IGN, SIGINT, SIGTERM
STDARG.H可變參數:va_list, va_start, va_arg, va_end (vprintf 等實現基礎)
STDDEF.H標準定義:NULL, offsetof, size_t, ptrdiff_t, wchar_t
STDIO.H標準 I/O 庫:printf, scanf, fopen, fclose, fread, fwrite, fseek, stdin/stdout/stderr
STDLIB.H實用程序:malloc, free, exit, abort, atexit, qsort, bsearch, abs, labs, strtol, rand, srand
STRING.H字符串操作:strcpy, strncpy, strcat, strcmp, strncmp, strlen, strchr, strstr, strtok, memset, memcpy, memmove
SYS\STAT.H文件狀態:stat, fstat, S_IFMT, S_IFREG, S_IFDIR, S_IRUSR, S_IWUSR
SYS\TYPES.H基本系統類型:time_t, off_t, ino_t, dev_t, pid_t
SYS\TIME.H時間類型:time_t, struct timeb (ftime)
TIME.H時間轉換:asctime, ctime, gmtime, localtime, strftime, difftime, clock, struct tm
VALUE.H機器相關極限常量:MAXLONG, MAXDOUBLE, HIBITS, FLOAT_MAX

ISO C 標準頭文件 (24項,現代開發核心)

<assert.h> <complex.h> <ctype.h> <errno.h> <fenv.h> <float.h>
<inttypes.h> <iso646.h> <limits.h> <locale.h> <math.h>
<setjmp.h> <signal.h> <stdarg.h> <stdbool.h> <stddef.h>
<stdint.h> <stdio.h> <stdlib.h> <string.h> <tgmath.h>
<time.h> <wchar.h> <wctype.h>

POSIX 標準頭文件 (Linux/Unix 系統編程必備)

標準 C++ 頭文件 (54項,含 STL 16容器)

<algorithm> <bitset> <cassert> <cctype> <cerrno> <cfloat> <ciso646> <climits> <clocale> <cmath> <complex> <csetjmp> <csignal> <cstdarg> <cstddef> <cstdio> <cstdlib> <cstring> <ctime> <cwchar> <cwctype>
<deque> <exception> <fstream> <functional> <iomanip> <ios> <iosfwd> <iostream> <istream> <iterator> <limits> <list> <locale> <map> <memory> <new> <numeric> <ostream> <queue> <set> <sstream> <stack> <stdexcept> <streambuf> <string> <strstream> <typeinfo> <utility> <valarray> <vector>
附加非必須:<hash_map> <hash_set> <slist> (SGI STL 遺產,C++11 標準庫已用 unordered_map/set 替代)

工程實踐建議

  1. 最小包含原則:.h 中只包含必需的頭文件,能前向聲明就前向聲明,減少編譯依賴與編譯時間。
  2. 標準庫優先:優先使用 ISO C/C++ 標準頭文件,避免依賴 Turbo C、POSIX、Windows 專有頭文件,提升可移植性。
  3. 模塊化設計:自定義模塊頭文件只暴露接口(函數原型、類型定義),實現細節隱藏在 .c/.cpp 中。
  4. 編譯器警告全開:-Wall -Wextra -Wpedantic -Werror 捕獲隱式聲明、類型不匹配等頭文件相關問題。

總結

頭文件是 C/C++ 模塊化編程的契約介面。從 Turbo C 時代的 31 個經典頭文件,到 ISO C 24 標準庫、POSIX 系統編程擴展、C++ 54 標準庫 (含 STL),熟練掌握**核心頭文件功能分類、常用函數/宏歸屬、包含依賴管理**,是高效開發、跨平台移植、避免符號衝突的基石技能。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved
類別頭文件 (部分)
目錄/文件<dirent.h> <fcntl.h> <fnmatch.h> <glob.h> <unistd.h> <utime.h> <wordexp.h>
用戶/組<pwd.h> <grp.h> <utmpx.h>
正則/模式<regex.h> <fnmatch.h> <glob.h>
網絡/套接字<netdb.h> <arpa/inet.h> <net/if.h> <netinet/in.h> <netinet/tcp.h> <sys/socket.h> <sys/un.h>
IPC/同步<sys/ipc.h> <sys/msg.h> <sys/sem.h> <sys/shm.h> <pthread.h> <semaphore.h> <sched.h> <mqueue.h>
內存/映射<sys/mman.h> <sys/uio.h>
時間/進程<sys/time.h> <sys/times.h> <sys/wait.h> <sys/resource.h> <sys/statvfs.h> <sys/utsname.h>