- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Ansi C compiler inconsistency ?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2004 12:37 AM
03-11-2004 12:37 AM
Ansi C compiler inconsistency ?
int main()
{
long int l = 0;
int i = 0;
short int s = 0;
i = (int) (l & 0xffffffff);
s = (short int) (l & 0xffff);
s = (short int) (i & 0xffff);
return 0;
}
reports a warning 'line 7, warning 740: Casting to a smaller size may truncate value' when compiling it with the command
cc -Aa -DD64 +w1
Why do I get this warning when casting a long to an int and not when casting the same long to a short, or casting an int to a short ?
And second is there a way to circumvent this warning other then specifying +W740 in the cc command ?
I'm trying to eliminate as much warnings as possible from my code, but I don't see a way to get rid of this one.
Thanks
Johan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2004 01:23 AM
03-11-2004 01:23 AM
Re: Ansi C compiler inconsistency ?
and it ran just fine with no complaints.
Could you check again please..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2004 01:42 AM
03-11-2004 01:42 AM
Re: Ansi C compiler inconsistency ?
For the record, I see this behavior on: HP-UX 11.0
with C compiler
cpp.ansi: HP92453-01 A.11.01.20 HP C Preprocessor (ANSI)
ccom: HP92453-01 A.11.01.20 HP C Compiler
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2004 01:57 AM
03-11-2004 01:57 AM
Re: Ansi C compiler inconsistency ?
int main()
{
long l=-1;
unsigned int i=1;
if( l > i ) printf("ilp32");
else printf("lp64");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2004 02:08 AM
03-11-2004 02:08 AM
Re: Ansi C compiler inconsistency ?
cc: "p1.c", line 6: warning 734: Different types treated as signed for >.
And some warnings about printf and not returning a value
It outputs:
lp64
Johan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2004 02:14 AM
03-11-2004 02:14 AM
Re: Ansi C compiler inconsistency ?
To compile it immediately please find a compiler or a different machine where you would get ilp32.
The output of the program is to be used :
ilp32 means -1 is promoted to uint32.
lp64 means both are promoted to signed 64.
I got a dig more to find out if this is a problem,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2004 02:56 AM
03-11-2004 02:56 AM
Re: Ansi C compiler inconsistency ?
BTW there is a mistake in my original post the cc command should state +DD64 and not -DD64. Obviously I used the +DD64 switch.
Seems to me that your code snipped shows a problem in the environments where ilp32 is returned. This problem can be eliminated through a typecast 'if( l > (long) i ) '
but that's not the point.
In my opinion the fact that you use a typecast, indicates that there is a potential problem, which you are aware of and accept. If you can't accept the consequences you have to reprogram IMO.
That's why I'm surprised that I get a warning on the long to int typecast in my original post.