[英]Why cant i check if i have included stdlib.h on tdm-gcc compiler?
I'm writing a header file in C and need stdlib.h
for it to work.我正在 C 中编写 header 文件,并且需要
stdlib.h
才能工作。 But, when I check if _STDLIB_H
is defined, the pre-processor says it's not, even if I include the file.但是,当我检查是否定义了
_STDLIB_H
时,预处理器说它不是,即使我包含了文件。 I have tried it on multiple compilers, where it works on most but not on tdm-gcc
.我已经在多个编译器上尝试过它,它适用于大多数但不适用于
tdm-gcc
。 How can I fix this?我怎样才能解决这个问题?
For a safer way to check if stdlib.h
is properly included, you should check for a macro that the C standard requires the file to define.为了更安全地检查
stdlib.h
是否正确包含,您应该检查 C 标准要求文件定义的宏。
I may be missing something, but I don't see any requirement in the C standard for stdlib.h
to define _STDLIB_H
.我可能遗漏了一些东西,但我在 C 标准中没有看到任何要求
stdlib.h
定义_STDLIB_H
。 I think this may just be a common way compilers decided to guard against multiple inclusion.我认为这可能只是编译器决定防止多重包含的一种常见方式。
try something like尝试类似的东西
#include <stdlib.h>
#ifndef NULL
#error "stdlib.h not included"
#endif
because the C standard requires that stdlib.h
defines NULL
因为 C 标准要求
stdlib.h
定义NULL
But none of this should be technically necessary... I don't know of a preprocessor that won't throw a fatal error if it can't find a file you tried to #include
但这在技术上都不是必需的......我不知道如果找不到您尝试
#include
的文件时不会抛出致命错误的预处理器
EDIT:编辑:
According to the C standard stdio.h
also defines NULL
, so perhaps it would be better to check for EXIT_SUCCESS
or EXIT_FAILURE
根据 C 标准
stdio.h
还定义了NULL
,所以检查EXIT_SUCCESS
或EXIT_FAILURE
可能会更好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.