我见过这样的代码:
#if !defined(errno)
extern int errno;
#endif因此,我的问题是errno是int还是宏,因为使用#if,if可以检查宏定义与否,以及在执行extern int errno;之后。
在errno.h中,定义如下
#ifdef _ERRNO_H
/* Declare the `errno' variable, unless it's defined as a macro by
bits/errno.h. This is the case in GNU, where it is a per-thread
variable. This redeclaration using the macro still works, but it
will be a function declaration without a prototype and may trigger
a -Wstrict-prototypes warning. */
#ifndef errno
extern int errno;
#endif
#endif 发布于 2013-01-28 06:15:04
在C++ (截至n3376)中,errno被定义为宏,如果您不包含,则它是在C中定义的任何内容(考虑到以上情况,我怀疑是int (但您需要查看C标准(如下所示:“errno是宏还是标识符”))。
n3376:
19.4错误编号错误
报头如表43所示。它的内容与POSIX 相同,只是errno将定义为一个宏。
发布于 2013-01-28 06:15:33
http://www.cplusplus.com/reference/cerrno/errno/ .It显示,标准将errno定义为c++的宏。
这个宏扩展为int类型的可修改的lvalue,因此它可以被程序读取和修改。 在C++中,errno总是声明为宏,但在C中也可以实现为带有外部链接的int对象。
优先选择添加了一些关于C++11的更多细节。
errno是一个预处理宏,它扩展到静态(直到C++11) /线程本地(自C++11)可修改的int类型的lvalue。
https://stackoverflow.com/questions/14556336
复制相似问题