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. Advertisements

  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. Advertisements

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:
    13,876
  2. =?Utf-8?B?UmFlZCBTYXdhbGhh?=

    Difference between casting by as and normal cast

    =?Utf-8?B?UmFlZCBTYXdhbGhh?=, Aug 15, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    513
    Brock Allen
    Aug 15, 2005
  3. Santa
    Replies:
    1
    Views:
    1,434
    Mark A. Odell
    Jul 17, 2003
  4. Sharon
    Replies:
    4
    Views:
    1,324
    CBFalconer
    Nov 17, 2003
  5. Mike Moum

    string.atoi and string.atol broken?

    Mike Moum, Jan 25, 2005, in forum: Python
    Replies:
    19
    Views:
    883
    Peter Otten
    Jan 27, 2005
  6. narsing
    Replies:
    2
    Views:
    1,100
    Thomas Weidenfeller
    Oct 23, 2006
  7. Nishu
    Replies:
    6
    Views:
    445
    Serve Laurijssen
    Feb 17, 2007
  8. PerlFAQ Server
    Replies:
    0
    Views:
    551
    PerlFAQ Server
    Jan 6, 2011
Loading...