sip*_*ihr 5 c linux header include dirent.h
当我们包括<dirent.h>和<limits.h>交流文件,dirent结构d_name变量显示We must not include limits.h!在IDE中的变量描述。当我查看文件/usr/include/x86_64-linux-gnu/bits/dirent.h时,它包含以下代码段。
...
struct dirent
{
#ifndef __USE_FILE_OFFSET64
__ino_t d_ino;
__off_t d_off;
#else
__ino64_t d_ino;
__off64_t d_off;
#endif
unsigned short int d_reclen;
unsigned char d_type;
char d_name[256]; /* We must not include limits.h! */
};
...
Run Code Online (Sandbox Code Playgroud)
我的问题是为什么我们不应该包括在内limits.h。我已经在网上搜索过,但找不到满意的答案。
每个标准标头都有其公开内容或可能公开内容的规范。dirent.h自曝struct dirent,DIR和相关功能,并保留字符开头的名称d_。也允许某些标头,但不要求公开某些其他标头公开的内容;dirent.h不是其中之一。因此,间接包含limits.h将违反名称空间,并破坏符合条件的程序,这些程序假定它们可以使用limits.h为自己的标识符公开的名称。