atoi error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan Pop

    #16
    Re: atoi error

    In <cgcv6r$fdk$1@p c-news.cogsci.ed. ac.uk> richard@cogsci. ed.ac.uk (Richard Tobin) writes:
    [color=blue]
    >In article <cgcso4$n4p$1@s unnews.cern.ch> , Dan Pop <Dan.Pop@cern.c h> wrote:
    >[color=green]
    >>There is little point in speculating about the actual effects of signed
    >>arithmetic overflow or about the possible tests the implementor may
    >>have used in order to avoid it hapenning.[/color]
    >
    >This is, supposedly, someone having problems with a real program. If
    >the result he gets is not one plausibly caused by overflow, then he
    >may have another error, and to ignore it would be unwise.[/color]

    How do you know overflow actually did happen?
    [color=blue]
    >The fact that nature of undefined behaviour is often quite predictable
    >is of great value in debugging.[/color]

    Indeed, if you have access to the actual code and know the exact effect
    of that particular instance of undefined behaviour on that particular
    platform. Which is not the case here. Without seeing the actual atoi
    code, there is no way to predict the result of the code in question.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email: Dan.Pop@ifh.de

    Comment

    • Dave Thompson

      #17
      Re: atoi error

      On Sat, 21 Aug 2004 04:06:31 GMT, bowsayge
      <bowsayge@nomai l.afraid.org> wrote:
      [color=blue]
      > Rodion said to us:[color=green]
      > > atoi [of] "1097400000 0";[/color][/color]
      [color=blue]
      > Forgive Bowsayge because this is not ANSI-C, but if you have
      > a compiler with the "long long" datatype (e.g. gcc), this works:
      >[/color]
      long long >= 64 bit is standard as of C99; which actually is, as C90
      was, an ISO standard, adopted by ANSI (but only in 2000). And you need
      library support as well, especially true of gcc since it can be used
      with multiple libraries whereas many other compilers are tied to one.
      [color=blue]
      > char * str = "1097400000 0";
      > long long i = 0;
      > if (sscanf(str, "%lld", & i) > 0) {
      > printf("i=%lld\ n" , i);
      > }[/color]

      Can also use i = atoll (str) or better strtoll (str, NULL, 10).

      A correct C99 implementation has all three, but lack of the library
      routines is usually diagnosed by link time, while nonsupport of the
      sscanf modifier may not be detected until runtime or even at all.
      [color=blue]
      >
      > You have a lot of insignificant zeros in that number. Perhaps
      > floating-point variables will suit you.[/color]

      Why do you think they're insignificant? The OP didn't say anything
      about error bars or uncertainty. All we know is they're trailing.

      - David.Thompson1 at worldnet.att.ne t

      Comment

      Working...