当前位置: 技术问答>linux和unix
求教在《UNIX C高级编程》中的一道程序
来源: 互联网 发布时间:2015-11-05
本文导语: 该程序在UNIX C高级编程第360页,程序15-6: int recv_fd(int servfd, ssize_t (*userfunc)(int, const void *, size_t)) { int newfd, nread, flag, status; char *ptr, buf[MAXLINE]; struct strbuf dat; struct strrecvfd recvfd; status = -1; for ( ;...
该程序在UNIX C高级编程第360页,程序15-6:
int
recv_fd(int servfd, ssize_t (*userfunc)(int, const void *, size_t))
{
int newfd, nread, flag, status;
char *ptr, buf[MAXLINE];
struct strbuf dat;
struct strrecvfd recvfd;
status = -1;
for ( ; ; ) {
dat.buf = buf;
dat.maxlen = MAXLINE;
flag = 0;
if (getmsg(servfd, NULL, &dat, &flag) >把status = *ptr & 255写成status = *ptr & 0x000000ff就好理解了
这里利用了默认常数为int型,并且int在32位机上是4字节,当然还有接受结果的内存status大于1字节。这里只要有一个条件不满足,都不能达到目的。
比如
status = *ptr & (char) 255
你再看看结果,是负数的还是负数。
int
recv_fd(int servfd, ssize_t (*userfunc)(int, const void *, size_t))
{
int newfd, nread, flag, status;
char *ptr, buf[MAXLINE];
struct strbuf dat;
struct strrecvfd recvfd;
status = -1;
for ( ; ; ) {
dat.buf = buf;
dat.maxlen = MAXLINE;
flag = 0;
if (getmsg(servfd, NULL, &dat, &flag) >把status = *ptr & 255写成status = *ptr & 0x000000ff就好理解了
这里利用了默认常数为int型,并且int在32位机上是4字节,当然还有接受结果的内存status大于1字节。这里只要有一个条件不满足,都不能达到目的。
比如
status = *ptr & (char) 255
你再看看结果,是负数的还是负数。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。