Velocity Reviews > Re: difference between casting and atol,atoi functions

# Re: difference between casting and atol,atoi functions

Olaf
Guest
Posts: n/a

 02-15-2005
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" <(E-Mail Removed)> wrote in message news:<cuccv5\$(E-Mail Removed)>...
> 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