首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >errno是errno.h中的int或宏。

errno是errno.h中的int或宏。
EN

Stack Overflow用户
提问于 2013-01-28 06:07:40
回答 2查看 2K关注 0票数 3

我见过这样的代码:

代码语言:javascript
复制
#if !defined(errno)
extern int errno;
#endif

因此,我的问题是errno是int还是宏,因为使用#if,if可以检查宏定义与否,以及在执行extern int errno;之后。

在errno.h中,定义如下

代码语言:javascript
复制
#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 
EN

回答 2

Stack Overflow用户

发布于 2013-01-28 06:15:04

在C++ (截至n3376)中,errno被定义为宏,如果您不包含,则它是在C中定义的任何内容(考虑到以上情况,我怀疑是int (但您需要查看C标准(如下所示:“errno是宏还是标识符”))。

n3376:

19.4错误编号错误

报头如表43所示。它的内容与POSIX 相同,只是errno将定义为一个宏。

票数 2
EN

Stack Overflow用户

发布于 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。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14556336

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档