PPC and atoi

Discussion in 'C++' started by senthil kumar, May 1, 2004.

  1. 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
     
    senthil kumar, May 1, 2004
    #1
    1. Advertising

  2. "senthil kumar" <> wrote in message
    news:...
    > 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
     
    John Harrison, May 1, 2004
    #2
    1. Advertising

  3. senthil kumar

    Julie Guest

    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.
     
    Julie, May 1, 2004
    #3
  4. "John Harrison" <> wrote in message news:<c70p6m$gl16s$-berlin.de>...
    > "senthil kumar" <> wrote in message
    > news:...
    > > 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.
     
    senthil kumar, May 2, 2004
    #4
  5. "senthil kumar" <> wrote in message
    news:...
    > "John Harrison" <> wrote in message

    news:<c70p6m$gl16s$-berlin.de>...
    > > "senthil kumar" <> wrote in message
    > > news:...
    > > > 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
     
    John Harrison, May 2, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian A. York

    mxtextools, py2app, and intel vs. PPC

    Ian A. York, Jun 5, 2007, in forum: Python
    Replies:
    0
    Views:
    243
    Ian A. York
    Jun 5, 2007
  2. Martin

    Supporting PPC 2003 and Mobile 5

    Martin, Jan 5, 2006, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    120
    Martin
    Jan 5, 2006
  3. Harry Simpson

    PPC 2002 and Webservices problem?

    Harry Simpson, Jun 16, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    119
    Harry Simpson
    Jun 16, 2004
  4. Julian Tarkhanov
    Replies:
    1
    Views:
    102
    Julian Tarkhanov
    Sep 29, 2007
  5. Sérgio Durigan Júnior

    Tests failed on PPC and PPC64

    Sérgio Durigan Júnior, Jun 2, 2008, in forum: Ruby
    Replies:
    2
    Views:
    93
    Sérgio Durigan Júnior
    Jun 2, 2008
Loading...

Share This Page