sam said:
Hi,
I want to ask question about following:-
#define SIZE 6000
long ret=0x00001515;
char buf[SIZE+5];
*(long*)&buf[strlen(buf)]=ret;
what exactly happenning at the last line of code.
That is a type cast, dereference and assignment. Very non-portable code
BTW - on some machines it will crash and on some it will arrange bytes
differently.
Assuming that between the definition of buf and the last line, there is
an initialization of buf taking place, what is happening is that it is
placing at the end of the null terminated string in buf a long.
e.g. if buf contained the sequence 'a', 'b', 'c', '\0', x, x, x, y then,
assuming long is a 4 byte type, the nul and the locations marked as 'x'
will be replaced with the contents of "ret" which could be 0x15, 0x15,
0, 0 -or- 0, 0, 0x15, 0x15 or some other machine dependant format of
"long" (could be 64 bit or 16 bit, you jusy don't know).