Mail Archives: djgpp/1996/04/04/01:51:59
In <315F1AEF DOT 5A083C32 AT alcyone DOT com> Erik Max Francis <max AT alcyone DOT com> writes:
>GEORGE GAGHON wrote:
>> int w_stuff
>> long l_stufftoo
>> byte b_stuffalso
>>
>> w_stuff = *p <---- will this grab a word at location p
>> l_stufftoo = *(p+2)<---- will this grab a long ?
>> b_stuffalso = *(p+6) <--- and this will grab a byte, right?
>No. It depends on what kind of pointer p is. Say that p is declared as a
>char *. Then *p (or, equivalently, p[0]) would get the char at p, *(p + 2)
>(or p[2]) would get the char at p + 2, and *(p + 6) (p[6]) would get the char
>at p + 6. Since the pointer is a char * (or whatever), dereferencing it gives
>you a char (or whatever). If you want to dereference to get other values, you
>have to explicitly cast it before dereferencing; i.e., *(int *) p.
>--
>Erik Max Francis &tSftDotIotE && http://www.alcyone.com/max && max AT alcyone DOT com
>San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect
>H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade
>Omnia quia sunt, lumina sunt. && Dominion, GIGO, GOOGOL, Omega, Psi, Strategem
>"Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_
also, don't forget that DJGPP is a 32bit compiler, so data sizes are different:
int = 4 bytes = dword
short = 2 bytes = word
char = 1 byte = byte
--
Fabian Nunez, Bsc(hons) student, University of Cape Town
email:fnunez AT cs DOT uct DOT ac DOT za web:http//www.cs.uct.ac.za/~fnunez
----------------------------------------------------------------
"k3wl aRe th3 lAmErz, 4 thEy sh4ll RulE!" - from the ElitE Bible
- Raw text -