编译问题 [英] Compiler Issue

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

问题描述

Hi Folks,


我们在编译器susch上遇到以下代码问题:xlc,gcc和但是icc成功通过。


示例代码:

int main(无效)

{

typedef unsigned char oratext;

typedef oratext text;


oratext c [2];

oratext * c_ptr = c;


text ** c_pptr;


c_pptr =&(oratext *)c_ptr;

}


错误:

" a.c",第11.11行:1506-017(S)地址运算符的操作数必须是左值或函数指示符。


似乎编译器无法解析其单遍中的所有地址。如果我们把它分成步骤就可以了。


修改后的代码:

int main(无效)

{

typedef unsigned char oratext;

typedef oratext text;


oratext c [2];

oratext * c_ptr = c;

text * c_ptr1;


c_ptr1 =(oratext *)c_ptr;


text * * c_pptr;


c_pptr =& c_ptr1;


}


这是一个众所周知的问题?还有其他工作可以解决这个问题吗?


TIA


Himanshu

Hi Folks,

We are encountering the following code issue on compiler susch as "xlc","gcc" but "icc" passes it successfully.

Sample code:
int main(void)
{
typedef unsigned char oratext;
typedef oratext text;

oratext c[2];
oratext * c_ptr = c;

text ** c_pptr;

c_pptr = &(oratext *)c_ptr;
}

Error:
"a.c", line 11.11: 1506-017 (S) Operand of address operator must be an lvalue or function designator.

It seems the compiler is unable to resolve all the addresses in its single pass. If we split this into to steps it works.

Modified code:
int main(void)
{
typedef unsigned char oratext;
typedef oratext text;

oratext c[2];
oratext * c_ptr = c;
text * c_ptr1;

c_ptr1 = (oratext *)c_ptr;

text ** c_pptr;

c_pptr = &c_ptr1;

}

Is this a known issue? are there any other work arounds for such a problem?

TIA

Himanshu

推荐答案

网络公民写道:
嗨伙计们,

我们在编译器支持上遇到以下代码问题:
" xlc" ," GCC"但是icc成功传递。

示例代码:
int main(void)
{typedef unsigned char oratext;
typedef oratext text;

oratext c [2];
oratext * c_ptr = c;

text ** c_pptr;

c_pptr =&(oratext *)c_ptr ;
Hi Folks,

We are encountering the following code issue on compiler susch as
"xlc","gcc" but "icc" passes it successfully.

Sample code:
int main(void)
{
typedef unsigned char oratext;
typedef oratext text;

oratext c[2];
oratext * c_ptr = c;

text ** c_pptr;

c_pptr = &(oratext *)c_ptr;




当c_ptr已经是一个时,为什么要转换为oratext *?


c_pptr =& c_ptr;


-

Ian Collins。



Why cast to an oratext* when c_ptr already is one?

c_pptr = &c_ptr;

--
Ian Collins.


网络公民写道:
cyber citizen wrote:
嗨伙计,

我们在编译器susch上遇到以下代码问题:xlc,gcc和但是icc成功传递。

示例代码:
int main(void)
{typedef unsigned char oratext;
typedef oratext text;

oratext c [2];
oratext * c_ptr = c;

text ** c_pptr;

c_pptr =&(oratext *)c_ptr ;


错误:
" a.c",第11.11行:1506-017(S)地址运算符的操作数必须是左值或函数指示符。 />
似乎编译器无法解析其单遍中的所有地址。如果我们把它分成步骤就可以了。


Sun编译器给出警告:强制转换不会产生左值。

对于lint也是如此。这告诉我编译器不认为

有一个地址需要解决。如果你认为这是有意义的话。

。例如,如果c是char,我写&(int)c那么我希望返回什么

地址,可以以有用的

方式使用指向int的指针?我不认为这是可能的。


当然我注意到当你写c_pptr =&(oratext *)c_ptr

c_ptr已经是指向oratext的指针了,那又怎么样?您是否期望编译器注意到演员阵容是多余的并将整个

表达式视为c_pptr =& c_ptr?我不会。你为什么要使用演员




顺便说一下,下面这段简单的代码会产生类似的

警告:


int main(){

int a,* p,** p1;


p =& a;

p1 =&(int *)p;

返回0;

}


对我来说,令人不快的是,夹板在任何一种情况下都不会发出警告



这是一个已知的问题吗?还有其他任何解决这个问题的工作吗?
Hi Folks,

We are encountering the following code issue on compiler susch as "xlc","gcc" but "icc" passes it successfully.

Sample code:
int main(void)
{
typedef unsigned char oratext;
typedef oratext text;

oratext c[2];
oratext * c_ptr = c;

text ** c_pptr;

c_pptr = &(oratext *)c_ptr;
}

Error:
"a.c", line 11.11: 1506-017 (S) Operand of address operator must be an lvalue or function designator.

It seems the compiler is unable to resolve all the addresses in its single pass. If we split this into to steps it works.
The Sun compiler gives "warning: a cast does not yield an lvalue".
Same for lint. This suggests to me that the compiler does not think
that there is an address to be resolved. It makes sense if you think
about it. If c is a char for example and I write &(int)c then what
address would I expect to be returned which can be used in a useful
manner as a pointer to int ? I don''t think it''s possbile.

Of course I noticed that when you write c_pptr = &(oratext *)c_ptr
c_ptr is already a pointer to oratext but so what ? Would you expect
the compiler to notice that the cast is superfluous and treat the whole
expression as c_pptr = &c_ptr ? I wouldn''t. Why are you using a cast
anyway ?

By the way the following simpler piece of code yields a similar
warning:

int main() {
int a , *p , **p1 ;

p = &a ;
p1 = &(int *)p ;
return 0 ;
}

It was an unpleasant surprise to me that splint does not give a warning
in either case.
Is this a known issue? are there any other work arounds for such a problem?




之前我没碰到它但我并不感到惊讶。我不认为

它也是一个问题。只是松开多余的演员阵容和问题。是

解决了。


Spiros Bousbouras



I hadn''t come across it before but I wasn''t surprised. I don''t consider
it a
problem either. Just loose the superfluous cast and the "problem" is
solved.

Spiros Bousbouras


Ian Collins写道:
Ian Collins wrote:
网络公民写道:
cyber citizen wrote:
伙计们,

我们在编译器支持上遇到以下代码问题
" XLC"," GCC"但是icc成功传递。

示例代码:
int main(void)
{typedef unsigned char oratext;
typedef oratext text;

oratext c [2];
oratext * c_ptr = c;

text ** c_pptr;

c_pptr =&(oratext *)c_ptr ;
Hi Folks,

We are encountering the following code issue on compiler susch as
"xlc","gcc" but "icc" passes it successfully.

Sample code:
int main(void)
{
typedef unsigned char oratext;
typedef oratext text;

oratext c[2];
oratext * c_ptr = c;

text ** c_pptr;

c_pptr = &(oratext *)c_ptr;



当c_ptr已经是一个时,为什么要转换为oratext *?

c_pptr =& c_ptr;


Why cast to an oratext* when c_ptr already is one?

c_pptr = &c_ptr;



我知道那里的类型是多余的。怎么有什么区别c_pptr =&(oratext *)c_ptr;和_pptr =& c_ptr;


问候

Himanshu



I know the type cast there in superfluous. How ever whats the difference in c_pptr = &(oratext *)c_ptr; and _pptr = &c_ptr;

Regards
Himanshu


这篇关于编译问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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