你为什么会返回(0 * AP ++)? [英] Why would you return(0*ap++)?

查看:253
本文介绍了你为什么会返回(0 * AP ++)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是K&放大器; RC,这里是整个code: http://v6shell.org/history/if.c

It's K&R-C and here is the whole code: http://v6shell.org/history/if.c

看这个功能:

char *nxtarg() {
    if (ap>ac) return(0*ap++);
    return(av[ap++]);
}

1.Question:
为什么收益率(0 * AP ++)?好吧,你想返回0和1。但是像这样,为什么增加AP?它是比如果快(AP> AC){AP ++;返回0;}

2.Question: nxtarg的返回类型为的char * ,为什么会返回0,整数

2.Question: The return type of nxtarg has to be char*, why can you return 0, an integer?

推荐答案

这是一个小动作挤增量成返回零的声明。它在逻辑上等同于一个条件

This is a little trick to squeeze the increment into a statement that returns zero. It is logically equivalent to a conditional

if (ap > ac) {
    ap++;
    return 0;
}

或用逗号操作甚至更好:

return (ap++, (char *)0); // Thanks, Jonathan Leffler

请注意,由于在你的榜样零不是一个编译时间常数,前pression需要铸造成符合标准的:

Note that since zero in your example is not a compile-time constant, the expression needs a cast to be compliant with the standard:

if (ap>ac) return (char*)(0*ap++);

至于返回一个整数零变为,在指示器上下文中使用时,它被认为是等于指针

这篇关于你为什么会返回(0 * AP ++)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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