473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

PPC and atoi

Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil
Jul 22 '05 #1
4 1582

"senthil kumar" <se******@rogers.com> wrote in message
news:c8**************************@posting.google.c om...
Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil


Not unless you supply a small piece of sample code with the output you get
and the output you expected. It means no-one has to guess what you are
talking about and end up answering a different question from what you had in
mind.

The obvious issue that arises from your description is why you are using %u
on a signed quantity. The way to clear up that issue so that there is no
ambiguity is to POST SOME CODE!

john
Jul 22 '05 #2
senthil kumar wrote:

Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil


You are probably bumping against the limits of the signed type on your
architecture.

You need to make sure that your input string is less than or equal to INT_MAX.
Anything over that and you will experience impementation-dependent (undefined)
behavior.

Further, atoi returns an int, %u is for printing unsigned values. You will
need to carefully examine your code to make sure that any (implicit)
conversion/promotion doesn't produce unintended results.
Jul 22 '05 #3
"John Harrison" <jo*************@hotmail.com> wrote in message news:<c7************@ID-196037.news.uni-berlin.de>...
"senthil kumar" <se******@rogers.com> wrote in message
news:c8**************************@posting.google.c om...
Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly.
What i mean is the converted value when printed using "%u" is not correct.

anybody know a thing or two about this.

regards
senthil


Not unless you supply a small piece of sample code with the output you get
and the output you expected. It means no-one has to guess what you are
talking about and end up answering a different question from what you had in
mind.

The obvious issue that arises from your description is why you are using %u
on a signed quantity. The way to clear up that issue so that there is no
ambiguity is to POST SOME CODE!

john


#include <stdlib.h>

main() {

printf ("%u\n",(unsigned int)atoi("4294967295"));

}

basically the code resembles the above sample code. when i run the
above sample code after compiling using gcc it prints out the value
properly however on the PowerPC it truncates.
Jul 22 '05 #4

"senthil kumar" <se******@rogers.com> wrote in message
news:c8**************************@posting.google.c om...
"John Harrison" <jo*************@hotmail.com> wrote in message

news:<c7************@ID-196037.news.uni-berlin.de>...
"senthil kumar" <se******@rogers.com> wrote in message
news:c8**************************@posting.google.c om...
Hi

We've been noticing a problem with atoi conversion on PowerPC.

When we supply value > 2^31-1 to utmost 2^32-1 it doesn't work properly. What i mean is the converted value when printed using "%u" is not correct.
anybody know a thing or two about this.

regards
senthil


Not unless you supply a small piece of sample code with the output you get and the output you expected. It means no-one has to guess what you are
talking about and end up answering a different question from what you had in mind.

The obvious issue that arises from your description is why you are using %u on a signed quantity. The way to clear up that issue so that there is no
ambiguity is to POST SOME CODE!

john


#include <stdlib.h>

main() {

printf ("%u\n",(unsigned int)atoi("4294967295"));

}

basically the code resembles the above sample code. when i run the
above sample code after compiling using gcc it prints out the value
properly however on the PowerPC it truncates.


Truncates to what exactly?

From the C standard section 7.20.1 - [talking about atoi] If the value of
the result cannot be represented, the behaviour is undefined.

Use strtoul instead.

john
Jul 22 '05 #5

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

Similar topics

19
by: Mike Moum | last post by:
I think there may be a bug in string.atoi and string.atol. Here's some output from idle. > Python 2.3.4 (#2, Jan 5 2005, 08:24:51) > on linux2 > Type "copyright", "credits" or "license()"...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
5
by: Bansidhar | last post by:
atoi() function seems not to have any support for Hex, octal number. Usually when I read from a text file then it contain number like 0x232 etc. In this case atoi() fells. In case of itoa() there...
15
by: puzzlecracker | last post by:
does anyone know how to implement this function efficiently?
47
by: sudharsan | last post by:
Hi could you please explain wat atoi( ) function is for and an example how to use it?
13
by: ptq2238 | last post by:
Hi, I have written this code to help me learn C but I'm not sure why gcc - Wall is giving me an error when I compile Basically I want to read in a character then a number and then manipulate...
9
by: Would | last post by:
Hey, hopefully one of you can help me... I keep getting an unresolved external 'atoi(char)' and I dont know why.. here is the code #include <iostream> #include <stdlib.h> using namespace std; ...
11
by: Nezhate | last post by:
Hi all, Can you help me? Why this warning appears in the next simple code ? warning: passing argument 1 of ‘atoi’ makes pointer from integer without a cast. #include <stdio.h> #include...
50
by: Bill Cunningham | last post by:
I have just read atoi() returns no errors. It returns an int though and the value of the int is supposed to be the value of the conversion. It seems to me that right there tells you if there was...
10
by: 66650755 | last post by:
First,thanks for all who have answered my last question. if char string="12345"; how could I convert the string(that is "3") to an int by using atoi? I only want to convert...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...

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.