HP / UX Itanium C comiler& std C. [英] HP/UX Itanium C comiler & std C

查看:51
本文介绍了HP / UX Itanium C comiler& std C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将我们的应用程序移植到HP / UX 11.23 Itanium时,我遇到了这种情况,其中编译器的行为与任何其他UNIX

C / C ++编译器的行为不同在过去10年中遇到过(包括

其他HP-UX平台)。


请考虑以下代码:


#include< stdio.h>


int main()

{

char * ptr =" ; AB" ;;

char * ans;


ans =(* ptr ++)? ptr:"";


printf(答案是%s \ n,ans);


返回0;

}


运行时,我通常会看到:


答案是B


在Itanium上显示:


答案是AB


有几个HPUX编译器可供选择在这个平台上,但是他们都以同样的方式行事。编译器开关不会产生任何

的差异。我现在正在使用GCC,它正如我所期望的那样工作。

HPUX 11上的
aCC PA-RISC也显示AB。


有没有人遇到过这个问题,或者确认看到的结果我已经看不到ANSI C?


Sion。

While porting our application to HP/UX 11.23 Itanium, I came across
this situation where the compiler acts differently to any other UNIX
C/C++ compiler that I have come across in the last 10 years (including
other HP-UX platforms).

Consider the following code:

#include <stdio.h>

int main()
{
char *ptr = "AB";
char *ans;

ans = (*ptr++) ? ptr : "";

printf ("Answer is %s\n", ans);

return 0;
}

When running this, I would usually expect to see:

Answer is B

On Itanium it displays:

Answer is AB

There are a few HPUX compilers to choose from on this platform, but
they all behave in the same way. Compiler switches don''t make any
difference. I am now using GCC, which works as I expect.

aCC on HPUX 11 PA-RISC also displays "AB".

Has anyone come across this before or confirm that the results I''ve
seen are invalid for ANSI C?

Sion.

推荐答案

sr******@transoft.com (Sion Roberts)在

新闻中写道:ae ************************** @ posting.google.c om :
sr******@transoft.com (Sion Roberts) wrote in
news:ae**************************@posting.google.c om:
在将我们的应用程序移植到HP / UX 11.23 Itanium时,我遇到了这种情况,编译器的行为与任何其他UNIX的C / C ++编译器不同我在过去十年中遇到过(包括其他HP-UX平台)。

请考虑以下代码:

#include< stdio。 h>

int main()
{
char * ptr =" AB" ;;
char * ans;

ns =(* ptr ++)? ptr:"" ;;

printf(答案是%s \ n,ans);

返回0;
}

运行时,我通常会看到:

答案是B


否,除非您使用%c而不是% s。
在Itanium上显示:

答案是AB
While porting our application to HP/UX 11.23 Itanium, I came across
this situation where the compiler acts differently to any other UNIX
C/C++ compiler that I have come across in the last 10 years (including
other HP-UX platforms).

Consider the following code:

#include <stdio.h>

int main()
{
char *ptr = "AB";
char *ans;

ans = (*ptr++) ? ptr : "";

printf ("Answer is %s\n", ans);

return 0;
}

When running this, I would usually expect to see:

Answer is B
No, not unless you used %c instead of %s.
On Itanium it displays:

Answer is AB




这是正确的。字符串以空值终止。字符''B''不是''\ 0''

因此它与''A'一起打印。


-

- 马克 - >

-



This is correct. Strings are null terminated. The char ''B'' is not ''\0''
thus it gets printed along with ''A''.

--
- Mark ->
--


文章< Xn ******* *************************@130.133.1.4> ,

Mark A. Odell< od ******* @ hotmail.com>写道:
In article <Xn********************************@130.133.1.4> ,
Mark A. Odell <od*******@hotmail.com> wrote:
sr ****** @ transoft.com(Sion Roberts)在
新闻中写道:ae **************** **********@posting.google。 com:
sr******@transoft.com (Sion Roberts) wrote in
news:ae**************************@posting.google. com:
在将我们的应用程序移植到HP / UX 11.23 Itanium时,我遇到了这种情况,编译器的行为与任何其他UNIX的行为不同
C / C ++我在过去10年中遇到的编译器(包括其他HP-UX平台)。

请考虑以下代码:

#include< stdio .h>

int main()
{
char * ptr =" AB" ;;
char * ans;

ans =(* ptr ++)? ptr:"" ;;

printf(答案是%s \ n,ans);

返回0;
}

运行时,我通常会看到:

答案是B
While porting our application to HP/UX 11.23 Itanium, I came across
this situation where the compiler acts differently to any other UNIX
C/C++ compiler that I have come across in the last 10 years (including
other HP-UX platforms).

Consider the following code:

#include <stdio.h>

int main()
{
char *ptr = "AB";
char *ans;

ans = (*ptr++) ? ptr : "";

printf ("Answer is %s\n", ans);

return 0;
}

When running this, I would usually expect to see:

Answer is B



不,除非您使用%c而不是% s。



No, not unless you used %c instead of %s.



Um,%c将打印存储在ans中的指针值的最低8位,

作为ASCII角色(在大多数机器上 - 显然是O / T,当然......)



Um, %c would print the lowest 8 bits of the pointer value stored in "ans",
as an ASCII character (on most machines - obviously O/T, of course...)

在Itanium上显示:

答案是AB
On Itanium it displays:

Answer is AB



这是正确的。字符串以空值终止。字符''B''不是''\ 0''
因此它与''A'一起打印。



This is correct. Strings are null terminated. The char ''B'' is not ''\0''
thus it gets printed along with ''A''.




这个想法以上是:


ans =(* ptr ++)? ptr:"";


" ptr"是假定的在测试之后但在其获取并且分配给ans之前获得
值之前递增。这一组中的学生将会指出标准不要求这种行为。



The idea of the above is that in:

ans = (*ptr++) ? ptr : "";

"ptr" is "supposed" to be incremented after it is tested but before its
value is fetched and assigned to "ans". The pedants in this group will
probably point out that this behavior is not required by "the standard".


On星期一,2004年11月15日05:16:00 -0800,Sion Roberts写道:
On Mon, 15 Nov 2004 05:16:00 -0800, Sion Roberts wrote:
在将我们的应用程序移植到HP / UX 11.23 Itanium时,我遇到了这样的情况:编译器的行为与我在过去10年中遇到的任何其他UNIX C / C ++编译器(包括其他HP-UX平台)不同。

请考虑以下内容代码:

#include< stdio.h>

int main()
{
char * ptr =" AB";
char * ans;

ans =(* ptr ++)? ptr:"" ;;

printf(答案是%s \ n,ans);

返回0;
}

运行时,我通常会看到:

答案是B


正确,?:运算符定义了一个序列点它的第一个操作数

被评估。因此,在为第二个操作数读取ptr的值之前,递增ptr的副作用必须是完全的(这是因为* ptr ++是''A' '这不是空的)。因此,应该将指向字符串中第二个

字符的指针分配给ans。

在Itanium上显示:

答案是AB
While porting our application to HP/UX 11.23 Itanium, I came across this
situation where the compiler acts differently to any other UNIX C/C++
compiler that I have come across in the last 10 years (including other
HP-UX platforms).

Consider the following code:

#include <stdio.h>

int main()
{
char *ptr = "AB";
char *ans;

ans = (*ptr++) ? ptr : "";

printf ("Answer is %s\n", ans);

return 0;
}

When running this, I would usually expect to see:

Answer is B
Correct, the ?: operator defines a sequence point after its first operand
is evaluated. Therefore the side-effect of incrementing ptr must be
complete before the value of ptr is read for the second operand (which it
is because *ptr++ is ''A'' which is not null). So a pointer to the 2nd
character in the string should be assigned to ans.
On Itanium it displays:

Answer is AB




看起来你找到了一个真正的编译错误。


劳伦斯



Looks like you''ve found a bona fide compiler bug.

Lawrence


这篇关于HP / UX Itanium C comiler&amp; std C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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