我意识到这可能是特定于操作系统的,但我正在尝试编写跨平台的 GCC 代码。所以想知道是否真的最好避免这些,或者如果我被迫选择,哪个是更安全的选择。
最佳答案
header 名称的语法是 (C11, 6.4.7 par. 1):
header-name:
< h-char-sequence >
" q-char-sequence "
h-char-sequence:
h-char
h-char-sequence h-char
h-char:
any member of the source character set except
the new-line character and >
q-char-sequence:
q-char
q-char-sequence q-char
q-char:
any member of the source character set except
the new-line character and "
-
和_
都是基本源字符集的一部分(5.2.1 第 3 段)。但是该标准留下了很多与 #include
实现定义相关的内容。
在实践中,我没有发现使用它们有任何问题。我不知道有一个文件系统不允许或为它们分配特殊含义。 This Wikipedia article也没有列出一个。
关于C 包含路径 : Safe to use hyphen & underscore?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28497851/