k& r fopen和fillbuf [英] k&r fopen and fillbuf

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

问题描述

我对另一个关于堆栈溢出的问题有疑问:- c K& R fopen和fillbuf上的分段错误.在这个问题中,讨论了_iobuf结构中的标志.这些用作不同的访问模式.但是在枚举标志的下面,有一些标志的特定值.那么标志"将仅采用这些特定值还是这些是一些标准值,而标志也可以采用其他一些值?我的怀疑来自以下事实:在定义数组_iob时,仅给出了三个标准值(对于stdin,stdout,stderr)(共20个),因此fp也可以采用其他一些值(同时17个其他值) .第二个疑问是,如果标志只能采用定义的值,如(_READ,_WRITE等.),则在int _fillbuf()函数中代替编写

I have a question regarding the other question asked on stack overflow:- segmentation fault on c K&R fopen and fillbuf. In this question there is a discussion of flags in struct _iobuf. These are used as different access modes. But down here in enum flags there are are some particular values of flags. So will 'flag' take only these particular values or these are some standard values whereas flag can take some other values as well? My doubt arises from the fact that while defining the array _iob only the three standard values (for stdin, stdout, stderr) were given(out of 20) so the fp can take some other values as well(17 others at the same time). The second doubt is that if flag can take only the defined values like(_READ,_WRITE etc.), then in int _fillbuf() function in place of writing

if((fp->flag & (_READ|_EOF|_ERR))!=_READ)

我们可以写成

if((fp->flag==_WRITE || fp->flag== _UNBUF))

因为在给定的固定标志值中仍然有意义.

because out of the given fixed flag values it still makes sense.

推荐答案

枚举值是标志位,flag成员可以设置其中的几个. (并非所有组合都是有意义的,但许多组合都是有意义的; __READ__EOF__ERR标志彼此独立,并且所有八个组合都是可能的.)

The enum values are flag bits and the flag member can have several of them set. (Not all combinations are meaningful, but many are; the __READ, __EOF and __ERR flags are independent of each other and all eight combinations are possible.).

因此

if((fp->flag & (_READ|_EOF|_ERR))!=_READ)

测试文件已打开以供读取,并且未设置错误或EOF标志.

Tests that the file is open for reading and has neither the error nor the EOF flags set.

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

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