& errno,sizeof errno [英] &errno, sizeof errno

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

问题描述

大家好,

一个快速的 - 因为errno是一个左值,我能做到:


fread(& errno,sizeof errno,1 ,fp)




TIA

viza

Hi all,
A quick one - since errno is a lvalue, can I do:

fread( & errno, sizeof errno, 1, fp )

?
TIA
viza

推荐答案

2008年9月12日星期五01:22:47 GMT,viza

< to @@mm-il.com.obviouschange.invalidwrote in comp.lang .c:
On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:

大家好,

一个快速的 - 因为errno是左值,我可以这样做:
Hi all,
A quick one - since errno is a lvalue, can I do:



只是因为errno是左值,没有。


但是因为errno需要产生一个可修改的左值,你需要

这么认为,但不一定。


标准不要求errno是对象的名称,它

可能是一个宏。


标准在脚注中显示了一个可能的宏实现:


"宏errno不必是对象的标识符。可能会将
扩展为函数调用产生的可修改的左值(对于

示例,* errno())。"

Just because errno is an lvalue, no.

But because errno is required to yield a modifiable lvalue, you would
think so, but not necessarily.

The standard does not require that errno be the name of an object, it
might be a macro.

The standard shows a possible macro implementation in a footnote:

"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."


fread(& errno,sizeof errno,1,fp)
fread( & errno, sizeof errno, 1, fp )



作为宏的errno标准中给出的示例将起作用

你想要的方式。


我不能想到一个宏会扩展到可修改的左值和

但是没有工作,但是我可以,如果我把它放在心上,而其他人在这里

几乎肯定会。


另一个潜在的问题是fread允许(),但不是

,将基础左值设置为除0以外的任何值,以防

出错或仅仅为了它。


-

杰克克莱恩

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://c-faq.com/

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp .lang.learn.c-c ++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html

The example given in the standard for errno as a macro would work the
way you want.

I can''t think of a macro that would expand to a modifiable lvalue and
yet not work, but I''m I could if I put my mind to it, and others here
almost certainly will.

Another potential problem is that fread() is allowed, but not
required, to set the underlying lvalue to any value except 0, in case
of an error or just for the heck of it.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html




" Jack Klein" < ja ******* @ spamcop.netwrote in message

news:hk *********************** ********* @ 4ax.com ...

"Jack Klein" <ja*******@spamcop.netwrote in message
news:hk********************************@4ax.com...

星期五,2008年9月12日01:22:47 GMT,viza
在comp.lang.c中
<到****** @ gm-il.com.obviouschange.invalidwrote:
On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:

>大家好,
一个快速的 - 因为errno是一个左值,我可以这样做:
>Hi all,
A quick one - since errno is a lvalue, can I do:



因为errno是一个左值,没有。


但是因为errno需要产生一个可修改的左值,你会这样想,但不一定。


标准没有要求errno是对象的名称,它

可能是一个宏。


标准在脚注中显示了一个可能的宏实现:


"宏errno不必是对象的标识符。可能会将
扩展为函数调用产生的可修改的左值(对于

示例,* errno())。"


Just because errno is an lvalue, no.

But because errno is required to yield a modifiable lvalue, you would
think so, but not necessarily.

The standard does not require that errno be the name of an object, it
might be a macro.

The standard shows a possible macro implementation in a footnote:

"The macro errno need not be the identifier of an object. It might
expand to a modifiable lvalue resulting from a function call (for
example, *errno())."


> fread(& errno,sizeof errno,1,fp)
>fread( & errno, sizeof errno, 1, fp )



作为宏的errno标准中给出的示例可行

你想要的方式。


我想不出一个可以扩展到可修改左值的宏和

但是没有用,但如果我把它放在心上,我就可以,而其他人在这里

几乎肯定会。


The example given in the standard for errno as a macro would work the
way you want.

I can''t think of a macro that would expand to a modifiable lvalue and
yet not work, but I''m I could if I put my mind to it, and others here
almost certainly will.



啊,一个挑战......如果一个实现做了类似的事情:


struct {

__flags:16;

} __ errrno;


#define errno(__ errno .__ flags)


/ * :-) * /

Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)

/* :-) */


>

另一个潜在的问题是fread()是允许的,但不是
需要
,将基础左值设置为除0之外的任何值,以防

出错或仅仅为了它。
>
Another potential problem is that fread() is allowed, but not
required, to set the underlying lvalue to any value except 0, in case
of an error or just for the heck of it.



也有...


-

poncho

There is that, too...

--
poncho


On Thu,2008年9月11日22:47:27 -0400,Scott Fluhrer写道:
On Thu, 11 Sep 2008 22:47:27 -0400, Scott Fluhrer wrote:

" Jack Klein" ; < ja ******* @ spamcop.netwrote in message

news:hk *********************** ********* @ 4ax.com ...
"Jack Klein" <ja*******@spamcop.netwrote in message
news:hk********************************@4ax.com...

>星期五,2008年9月12日01:22:47 GMT,viza
< to******@gm-il.com.obviouschange.invalidwrote:
>On Fri, 12 Sep 2008 01:22:47 GMT, viza
<to******@gm-il.com.obviouschange.invalidwrote in comp.lang.c:

>> fread( & errno,sizeof errno,1,fp)
>>fread( & errno, sizeof errno, 1, fp )


作为宏的errno标准中给出的示例将以您想要的方式工作。
<我不能想象一个宏会扩展到一个可修改的左值而且还不起作用,但如果我把它放在心上,我就可以,而其他人在这里
几乎肯定会。


The example given in the standard for errno as a macro would work the
way you want.

I can''t think of a macro that would expand to a modifiable lvalue and
yet not work, but I''m I could if I put my mind to it, and others here
almost certainly will.



啊,一个挑战......如果一个实现做了类似的事情:


struct {

__flags:16;

} __ errrno;


#define errno(__ errno .__ flags)


/ * :-) * /


Ahh, a challange... What if an implementation did something like:

struct {
__flags : 16;
} __errrno;

#define errno (__errno.__flags)

/* :-) */



如果实现这样做,我会认为errno的类型是

而不是int(甚至如果int有16位)。相反,类型是int:16。另一个

可能性是

extern volatile int errno;

我认为类型是volatile int 。


但是,考虑一下:


注册int errno;


即使用户代码不允许使用

关键字寄存器定义静态对象,如果这是实现支持的扩展,

我认为对errno的任何要求都没有如果

实现使用它,则违反。

If the implementation does that, I would argue that the type of errno is
not int (even if int has 16 bits). Instead, the type is int : 16. Another
possibility is
extern volatile int errno;
where I would argue the type is volatile int.

However, consider this:

register int errno;

Even though user code is not permitted to define static objects with the
keyword register, if this is a supported extension by the implementation,
I don''t think any requirements on errno have been violated if the
implementation makes use of it.


这篇关于&amp; errno,sizeof errno的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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