473,769 Members | 5,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HP/UX Itanium C comiler & std C

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.
Nov 14 '05 #1
20 2333
sr******@transo ft.com (Sion Roberts) wrote in
news:ae******** *************** ***@posting.goo gle.com:
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


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

--
- Mark ->
--
Nov 14 '05 #2
In article <Xn************ *************** *****@130.133.1 .4>,
Mark A. Odell <od*******@hotm ail.com> wrote:
sr******@trans oft.com (Sion Roberts) wrote in
news:ae******* *************** ****@posting.go ogle.com:
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.


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...)
On Itanium it displays:

Answer is AB


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


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".

Nov 14 '05 #3
On Mon, 15 Nov 2004 05:16:00 -0800, Sion Roberts wrote:
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
Nov 14 '05 #4
Mark A. Odell wrote:

sr******@transo ft.com (Sion Roberts) wrote in
news:ae******** *************** ***@posting.goo gle.com:
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.


Answer is B.
ans points to a string regardless of whether it points
to the first or second element of "AB".

--
pete
Nov 14 '05 #5
Lawrence Kirby wrote:
On Mon, 15 Nov 2004 05:16:00 -0800, Sion Roberts wrote:

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.


Can someone please clarify what is meant by this text, from C99 §6.5.15
Conditional operator, #4.

"If an attempt is made to modify the result of a conditional operator or
to access it after the next sequence point, the behavior is undefined".

Does the "access it" part apply to the OP's code or am I just
misinterpreting the standard?

TIA
Bjørn

[snip]
Nov 14 '05 #6
Bjørn Augestad wrote:

Lawrence Kirby wrote:
On Mon, 15 Nov 2004 05:16:00 -0800, Sion Roberts wrote:

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.


Can someone please clarify what is meant by this text, from C99 §6.5.15
Conditional operator, #4.

"If an attempt is made to modify the result of a conditional
operator


I think it means that (a ? b : c) is an rvalue
and that you can't do something like this: ((a ? b : c)++)
or to access it after the next sequence point,
the behavior is undefined".
Does the "access it" part apply to the OP's code or am I just
misinterpreting the standard?


I don't know what that means.

--
pete
Nov 14 '05 #7
In article <cn**********@y in.interaccess. com>,
Kenny McCormack <ga*****@intera ccess.com> wrote:
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".


No. The standard says there is a sequence point after the first operand
of the ? operator.

-- Richard
Nov 14 '05 #8
On Mon, 15 Nov 2004 14:41:45 +0000, pete wrote:
Bjørn Augestad wrote:

Lawrence Kirby wrote:
> On Mon, 15 Nov 2004 05:16:00 -0800, Sion Roberts wrote:
>
>
>>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.


Can someone please clarify what is meant by this text, from C99 §6.5.15
Conditional operator, #4.

(rearranged to bring the standard text together)
"If an attempt is made to modify the result of a conditional
operator or to access it after the next sequence point,
the behavior is undefined".


I think it means that (a ? b : c) is an rvalue
and that you can't do something like this: ((a ? b : c)++)


That is true but I don't think it is what the text is for, because that is
caught by a constraint violation for ++ i.e. its operand must be a
modifiable lvalue. A constraint violation is the more significant error,
if you have a CV then further undefined behaviour is not an issue.

I'm wondering if this has something to do with "rvalue" structures e.g.

struct foo { int bar; } s1 = { 1 }, s2 = { 2 };

(expr ? s1 : s2).bar

but I haven't come up with an example that triggers undefined behaviour
from 6.5.15p4 and doesn't trip up elsewhere in the standard. That sentence
is an addition from C90, so either they spotted a case that hadn't been
spotted at the time of C90 or this has something to do with new C99
features.
Does the "access it" part apply to the OP's code or am I just
misinterpreting the standard?


I don't know what that means.


The standard talks about modifying the RESULT of the conditional
operator or accessing after the next sequence point, which the OPs code
does not do.

Lawrence

Nov 14 '05 #9
"Mark A. Odell" <od*******@hotm ail.com> wrote in
news:Xn******** *************** *********@130.1 33.1.4:
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.


Ignore me. I missed the increment on 'ptr' and the lack of dereference on
'ans'.

--
- Mark ->
--
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1812
by: Bernhard Mulder | last post by:
I am using Python on Itanium Windows 64 (Server 2003) with a Win32 version. Is there a native version available or planned? Are testers needed for this platform? Windows 64 is a bit unusual in that "long" is not large enough to hold an address.
0
1451
by: Bernard Delmée | last post by:
Hello, because we are migrating to an Itanium HP-UX server, I will shortly need to compile python 2.3 and cx_oracle on that platform. I seem to recall people having problem compiling python on HP-UX in general, and am interested in opinions about which compiler to use. Should I require the HP compiler, or is gcc known to work for this purpose ? Thanks for any hint,
1
2717
by: JB_Nikegolf | last post by:
I am replacing a production database. Initially I sized a Quad 2.8 GHz with 8 GB of Ram. I will be running Windows 2003 Enterprise Server with Sql Server 2000 Enterprise. I was wondering what kind of performance I would (better/worse) get from a Dual 1.5 GHz Itanium with 8 GB of Ram running the 64 bit versions of Windows 2003 and Sql Server. Hardware cost are pretty comparable, but I could save on Sql Server licenses. Anyone that has...
0
1334
by: Jack | last post by:
We are migrating an application to DB2 on Itanium and have 1 Java function. We are running RHEL AS 3.2 and have been able to upgrade Java on our x86 environment to IBMJava2 141 with no problems. I have not been able to find a copy of IBMJava2 141 for IA64 which makes me wonder whether it exists. If it does exist can someone tell me where. Otherwise, what are my options in the IA64 world? will IBMJava 131-9 work with DB2 on IA64? If...
1
932
by: onion | last post by:
who knows that software serves in order to compile a projetcs c++ (VC7) for ITANIUM with Windows Serveur 2003.
25
9738
by: John Gibson | last post by:
Hi, all. I need to upgrade my dual Xeon PostgreSQL engine. Assuming similar memory and disk sub-systems, I am considering a Quad Xeon system vs. a Dual Itanium for PostgreSQL. I believe that the PostgreSQL code is written for 32 bit and not optimized for the 64 bit Itanium cpu. That makes me think that the Xeon system would be a better choice.
14
1572
by: csgrimes1 | last post by:
Anyone know where else I can download 2.6 for x64 windows? Thanks!
1
2150
by: Christopher | last post by:
Hello, A tool that we use needs to be ported to Itanium. It wsa written for Python 2.5.2, and so I was happily using the Itanium version of that release. However, as I have gotten deeper into the port, I see that ctypes was not included with the Itanium Python 2.5.2 release. I need to compile that module for that release and platform, but I have been unable to discover which MS compiler version and runtime was used to generate the...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9416
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10199
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3551
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.