include 編譯後提示錯誤,『no such file』
`stdio_ext.h` 不是標準 C 庫頭文件,屬於 GNU C Library (glibc) 擴展,僅在 Linux/glibc 環境下可用,且非 POSIX 標準。
| 功能 | 標準頭文件 | 說明 |
|---|---|---|
| 標準輸入輸出 | ` | C89/C99 標準,所有編譯器支持 |
| 標準庫 | ` | 內存管理、轉換、隨機數等 |
| 字符串操作 | ` | memcpy、strcpy、strlen 等 |
| 字符處理 | ` | isalpha、toupper 等 |
| 數學函數 | ` | sin、cos、sqrt、pow 等 |
| 斷言 | ` | debug 斷言宏 |
| 可變參數 | ` | va_list、va_start 等 |
| 固定寬度整數 | ` | C99: int32_t、uint64_t 等 |
| 布爾類型 | ` | C99: bool、true、false |
// GNU 擴展:文件流擴展操作
size_t __fbufsize(FILE *stream); // 獲取緩衝區大小
size_t __fpending(FILE *stream); // 獲取緩衝區待寫入字節數
int __flbf(FILE *stream); // 判斷是否行緩衝
int __freadable(FILE *stream); // 判斷可讀
int __fwritable(FILE *stream); // 判斷可寫
int __freading(FILE *stream); // 判斷最後操作是讀
int __fwriting(FILE *stream); // 判斷最後操作是寫
int __fsetlocking(FILE *stream, int type); // 設置鎖定模式
void _flushlbf(void); // 刷新所有行緩衝流
這些功能在標準 C 中**無對應**,屬於底層系統編程接口。
// 刪除這行
// #include
// 只包含標準頭文件
#include
#include
#include
// ... 其他標準頭文件
重構為標準 C 或平台無關寫法:
// 原代碼(GNU 擴展)
if (__fpending(stdout) > 0) { ... }
// 重構:標準 C 無法直接獲取緩衝區待寫數據
// 方案:手動管理緩衝區或使用 fflush
fflush(stdout); // 強制刷新,確保數據寫入
#include // 系統包含路徑:/usr/include, /usr/local/include, 編譯器內置路徑
#include "myheader.h" // 當前源文件目錄 → 項目包含路徑 → 系統包含路徑
# GCC/Clang
gcc -xc -E -v - < /dev/null 2>&1 | grep "include" -A 20
# MSVC
cl /showIncludes source.c
結論:刪除 `#include