Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > PPC and atoi

Reply
Thread Tools

PPC and atoi

 
 
senthil kumar
Guest
Posts: n/a
 
      05-01-2004
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
 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      05-01-2004

"senthil kumar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
Julie
Guest
Posts: n/a
 
      05-01-2004
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.
 
Reply With Quote
 
senthil kumar
Guest
Posts: n/a
 
      05-01-2004
"John Harrison" <(E-Mail Removed)> wrote in message news:<c70p6m$gl16s$(E-Mail Removed)-berlin.de>...
> "senthil kumar" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) 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.
 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      05-02-2004

"senthil kumar" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> "John Harrison" <(E-Mail Removed)> wrote in message

news:<c70p6m$gl16s$(E-Mail Removed)-berlin.de>...
> > "senthil kumar" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: difference between casting and atol,atoi functions infobahn C Programming 1 02-15-2005 08:09 AM
Re: difference between casting and atol,atoi functions Olaf C Programming 0 02-15-2005 06:56 AM
string.atoi and string.atol broken? Mike Moum Python 19 01-27-2005 08:35 AM
what are the reverse functions of atof( ), atoi( ) and atol( ) ? Sharon C Programming 4 11-17-2003 10:13 AM
Confusing itoa and atoi Sona C Programming 2 09-22-2003 05:57 PM



Advertisments