Re: difference between casting and atol,atoi functions

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

  1. Olaf

    Olaf Guest

    Hello

    statement 1:
    the pointer value is casted to a pointer to a long
    wher the pointer directs to is the array of char, a long is 4 byte
    it gives *x = 0xFFFFFFFF

    statment 2:
    atol has only 1 parameter, a string
    char 255 is not a number in the ascii table
    so y = 0;

    if you put
    buf[0]='1'; // 0x31
    buf[1]='2'; // 0x32
    buf[2]='3'; // 0x33
    buf[3]='4'; // 0x34
    buf[4]='\0';

    atol(buf) => 1234
    x = (long *)buf;
    x is the adres of buf
    *x => 0x31323334 => 825373492

    so the diference is huge.

    Greetings Olaf

    "Janice" <> wrote in message news:<cuccv5$>...
    > 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
     
    Olaf, Feb 15, 2005
    #1
    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,225
  2. Gizmo
    Replies:
    5
    Views:
    428
    llewelly
    Sep 8, 2003
  3. Sharon
    Replies:
    4
    Views:
    999
    CBFalconer
    Nov 17, 2003
  4. Mike Moum

    string.atoi and string.atol broken?

    Mike Moum, Jan 25, 2005, in forum: Python
    Replies:
    19
    Views:
    679
    Peter Otten
    Jan 27, 2005
  5. infobahn
    Replies:
    1
    Views:
    339
    Randy Howard
    Feb 15, 2005
Loading...

Share This Page