C 語言標準不規定文件名大小寫敏感性,完全委託給底層操作系統文件系統。
| 平台 | 文件系統 | 大小寫敏感 | 備註 |
|---|---|---|---|
| Windows | NTFS/FAT32/exFAT | **不敏感** (Case-insensitive) | 但保留大小寫 (Case-preserving) |
| Linux | ext4/xfs/btrfs | **敏感** (Case-sensitive) | file.c ≠ File.c |
| macOS | APFS/HFS+ | **默認不敏感** (可格式化為敏感) | APFS 支持區分大小寫卷 |
| 嵌入式 | FatFS/LittleFS/YAFFS | 通常不敏感 | 視配置而定 |
my_module.c,CMakeLists.txt 同步;#include "MyModule.h" 而非 #include "mymodule.h",避免 Linux 編譯失敗;file(GLOB SRCS "src/*.c") 依賴文件系統遍歷順序,建議顯式列出;git ls-files | awk '/[A-Z]/ {print "大小寫違規: " $0}'。
#!/bin/bash
# check_case_sensitive.sh
find . -name "*.c" -o -name "*.h" | while read f; do
lower=$(echo "$f" | tr '[:upper:]' '[:lower:]')
if [ "$f" != "$lower" ]; then
echo "WARNING: $f contains uppercase"
fi
done