PPC and atoi

S

senthil kumar

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
 
J

John Harrison

senthil kumar said:
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
 
J

Julie

senthil said:
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.
 
S

senthil kumar

John Harrison said:
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.
 
J

John Harrison

senthil kumar said:
"John Harrison" <[email protected]> wrote in message



#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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top