Re: difference between casting and atol,atoi functions

Discussion in 'C Programming' started by infobahn, Feb 15, 2005.

  1. infobahn

    infobahn Guest

    Janice wrote:
    >
    > unsigned char buf[255];
    > signed long* x;
    > signed long y;
    > buf[0]=255;
    > buf[1]=255;
    > buf[2]=255;
    > buf[3]=255;
    > //statment 1
    > x=(signed long*)buf;
    > //statement 2
    > y=atol(buf,4);
    >
    > What is the difference between statement 1 and 2?
    > Thanx


    The difference is a subtle one. The first statement is stupid because
    it invokes undefined behaviour, whereas the second one is stupid
    because it invokes undefined behaviour.
    infobahn, Feb 15, 2005
    #1
    1. Advertising

  2. infobahn

    Randy Howard Guest

    In article <>,
    says...
    >
    > The difference is a subtle one. The first statement is stupid because
    > it invokes undefined behaviour, whereas the second one is stupid
    > because it invokes undefined behaviour.


    This would make a much better .sig candidate with the author's proper
    name attached.

    --
    Randy Howard (2reply remove FOOBAR)
    "Making it hard to do stupid things often makes it hard
    to do smart ones too." -- Andrew Koenig
    Randy Howard, Feb 15, 2005
    #2
    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. jakk
    Replies:
    4
    Views:
    12,131
  2. Gizmo
    Replies:
    5
    Views:
    428
    llewelly
    Sep 8, 2003
  3. Sharon
    Replies:
    4
    Views:
    987
    CBFalconer
    Nov 17, 2003
  4. Mike Moum

    string.atoi and string.atol broken?

    Mike Moum, Jan 25, 2005, in forum: Python
    Replies:
    19
    Views:
    672
    Peter Otten
    Jan 27, 2005
  5. Olaf
    Replies:
    0
    Views:
    621
Loading...

Share This Page