return(i = 1,NULL) [英] return (i = 1, NULL)

查看:70
本文介绍了return(i = 1,NULL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是合法的:


FILE * func(无效){

extern int errno;


return(errno = EINVAL,NULL);

}


我的编译器(openbsd上的gcc 2.9.x)抱怨我回来了

来自int w / oa cast的指针。然而,linux上的gcc 3.x从来没有对它进行窥视

,所以可能2.9.x只是脾气暴躁。


i假设相关的问题是,可以分一组不同的类型,比如

那个?


tia,


比尔

解决方案

Ben Pfaff< bl*@cs.stanford.edu>写道:

William Ahern< wi ***** @ wilbur.25thandClement.com>写道:

这是合法的:

FILE * func(void){
extern int errno;

返回(errno = EINVAL,NULL);
}



编号你不能自己声明`errno''那样的(它不一定是变量)而你忘了#include< stdio.h>。
如果你解决了这两个问题,那么是的。


是的。是的。*

如果你解决了这两个问题,那么是的。




这就是我的想法。比如。


- 比尔


* - http://www.ebaumsworld.com/arnolds3.html




William Ahern <无线***** @ wilbur.25thandClement.com>在消息新闻中写道:36 ************ @ wilbur.25thandClement.com ...

这是合法的:

FILE * func (void){
extern int errno;

返回(errno = EINVAL,NULL);
}
我的编译器(gcc 2.9.x on openbsd)抱怨说我正在从int w / oa cast返回一个
指针。然而,linux上的gcc 3.x从来没有对它有过窥视,所以2.9.x可能只是脾气暴躁。




为了避免讨论名称空间污染,让我改写

你的代码:


FILE * func(无效)

{

extern int my_errno;


return(my_errno = SOME_VALUE,NULL);

}


并且给return语句赋予的表达式不是常量

表达式,因为它包含逗号运算符。因此,在返回的

* full *表达式中,NULL不符合null

指针常量。如果你的实现#defines NULL只是为0(或

类似的类型与FILE *不兼容的那些),

你的程序是非法的,这就是gcc抱怨。

-

Jun,Woong(my******@hanmail.net)


< blockquote> William Ahern< wi ***** @ wilbur.25thandClement.com>在消息新闻中写道:< 36 ************ @ wilbur.25thandClement.com> ...

这是合法的:

FILE * func(void){
extern int errno;

返回(errno = EINVAL,NULL);
}

我的编译器(gcc 2.9 .x on openbsd)抱怨我从int w / oa cast返回了一个
指针。然而,Linux上的gcc 3.x从来没有对它进行过深入了解,所以可能2.9.x只是脾气暴躁。




编译器错误。顺便说一下,return语句不需要()。


Sam


is this legal:

FILE *func(void) {
extern int errno;

return (errno = EINVAL, NULL);
}

my compiler (gcc 2.9.x on openbsd) is complaining that i''m returning a
pointer from int w/o a cast. gcc 3.x on linux, however, never made a peep
about it, so possibly 2.9.x is just grumpy.

i suppose the relevent question is, can one group different types like
that?

tia,

Bill

解决方案

Ben Pfaff <bl*@cs.stanford.edu> wrote:

William Ahern <wi*****@wilbur.25thandClement.com> writes:

is this legal:

FILE *func(void) {
extern int errno;

return (errno = EINVAL, NULL);
}


No. You can''t declare `errno'' yourself like that (it''s not
necessarily a variable) and you forgot to #include <stdio.h>. If you fix those two problems, then yes.
yes. yeah.*
If you fix those two problems, then yes.



that''s what i thought. thanx.

- Bill

* - http://www.ebaumsworld.com/arnolds3.html



"William Ahern" <wi*****@wilbur.25thandClement.com> wrote in message news:36************@wilbur.25thandClement.com...

is this legal:

FILE *func(void) {
extern int errno;

return (errno = EINVAL, NULL);
}

my compiler (gcc 2.9.x on openbsd) is complaining that i''m returning a
pointer from int w/o a cast. gcc 3.x on linux, however, never made a peep
about it, so possibly 2.9.x is just grumpy.



To avoid the discussion on the name space pollution, let me rewrite
your code:

FILE *func(void)
{
extern int my_errno;

return (my_errno = SOME_VALUE, NULL);
}

And the expression given to the return statement is not a constant
expression, becuase it contains the comma operator. Therefore, in the
*full* expression for the return, NULL doesn''t qualify as a null
pointer constant. If your implementation #defines NULL simply as 0 (or
similar ones whose types are not assignment-compatible with FILE *),
your program is illegal, which is what gcc complains about.
--
Jun, Woong (my******@hanmail.net)


William Ahern <wi*****@wilbur.25thandClement.com> wrote in message news:<36************@wilbur.25thandClement.com>...

is this legal:

FILE *func(void) {
extern int errno;

return (errno = EINVAL, NULL);
}

my compiler (gcc 2.9.x on openbsd) is complaining that i''m returning a
pointer from int w/o a cast. gcc 3.x on linux, however, never made a peep
about it, so possibly 2.9.x is just grumpy.



Compiler bug. The return statement does not require ( ), incidentally.

Sam


这篇关于return(i = 1,NULL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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