C/C++ on Linux/Unix

Moderators: Lundin
Number of threads: 336
Number of posts: 663

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Not getting 64 bit specific truncation warnings. Posted by saurabhkaushal on 20 Feb 2009 at 11:34 PM
Dear All,

I am porting my C/C++ project (currently functioning on 32 bit machine) into 64 bit SUSUE linux machine
uname -a
Linux msglxd03 2.6.5-7.97-smp #1 SMP Fri Jul 2 14:21:59 UTC 2004 x86_64 x86_64 x86_64 GNU/Linux

I am trying to get the warning Specific to long to int and pointer to int assignments.

===================================
Written warnings2.c file which conatin :

#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned int i;
unsigned long z = -1L;

printf("size of unsigned is %d bytes!\n", sizeof(z));
printf("size of int is %d bytes!\n", sizeof(i));

i = z;
printf("\ni is = %d",i);
i = &z;
printf("\ni is = %d",i);
return 1;
}
==========================
After compiling (either with gcc or cc)

$ gcc -m64 -Wall -march=x86-64 -o war2.o warnings2.c

it gave me following warning:

warnings2.c: In function main:
warnings2.c:9: warning: format %d expects type int, but argument 2 has type long unsigned int
warnings2.c:10: warning: format %d expects type int, but argument 2 has type long unsigned int
warnings2.c:14: warning: assignment makes integer from pointer without a cast

There isn't any warning for long to int assignment(truncation) @ line 12.

On sparcv9 it is giving warnings when used >> CC +w2 -xarch=v9
"warnings2.cpp", line 12: Warning: Conversion of 64 bit type value to "int" causes truncation.
1 Warning(s) detected.

Could anybody please tell me how could we get the similar warnings on Linux?
Which all options are need with gcc to get the truncation warnings on 64-bit linux machine?
We have already tried -m64 -Wall -mcpu=x86-64 -Wconversion -pedantic and -Wshorten-64-to-32, but didn't get truncation warnings ?

Thanks in advance,

Regards.

Report
Re: Not getting 64 bit specific truncation warnings. Posted by Karpov2007 on 22 Feb 2009 at 3:31 AM
You can try C++Test:

WARNING: 3264bit_ImplicitTruncation (port-06)
int iVal = 72;
long lVal = 6;
iVal = lVal; -ERR

And/Or :)

You can come to us - http://www.Viva64.com
We concern of subjects porting code to 64-bit systems. We plan to let out a specialised product Viva64 for check 64-bit programs for Linux. I suggest to communicate. Write to me if it is interesting to you.

See also:
Comparison of analyzers’ diagnostic possibilities at checking 64-bit code
http://www.viva64.com/art-1-2-914146540.html

Yours faithfully, Andrey Karpov
Chief Technical Officer of
OOO "Program Verification Systems" (Co Ltd)
Visit us at our site: www.viva64.com
E-Mail: karpov@viva64.com



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.