了解Ç错误号 [英] Understanding C errno

查看:73
本文介绍了了解Ç错误号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的系统错误号定义为:

int *    __error(void);
#define errno    (* __error())

我理解错误号是一个宏,扩展到 * __error()功能:

I understand errno is a macro and expands to * __error() function:


  1. 我到处找(来源我的系统上),但我无法找到 __错误()函数的定义,有人可以显示/解释什么会/应该是它的定义是什么?

  1. I searched everywhere (source on my system) but I can't find the definition of the __error() function, can someone show/explain what would/should be the definition of it?

如何除权pression 错误号= 0 适用于上述定义(分配 0 一个功能?)?请问错误号= 0 扩展到 * __error()= 0

How the expression errno = 0 works with the above definition (Assigning 0 to a function?)? Does errno = 0 expands to * __error() = 0?

感谢

推荐答案

__误差函数返回一个指向错误号变量调用线程。在错误号宏解引用该指针,从而可以在一个两边出现左值等号。

The __error function returns a pointer to the errno variable for the calling thread. The errno macro dereferences that pointer, resulting in an lvalue that can appear on either side of an equals sign.

要回答你的问题:


  1. 该功能决定的正确地址为特定线程​​错误号变量。每个线程都有自己的。

  1. The function determines the correct address for the errno variable for that specific thread. Each thread gets its own.

是的,就变成(* __error())= 0; 这指定 0 来的线程的错误号变量。

Yes, it becomes (* __error()) = 0; which assigns 0 to that thread's errno variable.

这篇关于了解Ç错误号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆