pointers to functions, dereferencing, first byte of func
Donald McLachlan
don at dgbt.doc.ca
Wed Jan 30 14:13:15 AEST 1991
I recently wanted to write a nastly bit of code for a PC (self modifying)
so ...
char *c;
extern char func();
c = func;
some code putting new hex values into the address space of the function
now for the fun stuff. Under microsoft C, c[1] ... c[MAX_INT] worked,
but c[0] would sometimes bugger me up. *c had the exact same unreliable
results (as it should since *c is supposed to be identicle to c[0]).
what I had to do to get at the first byte of executable code was ...
char *c1;
c1 = &(c[1]);
--c1; /* should equal c[0] */
*c1 = char constant.
hows that for bastardising code to fool a compiler!!!
More information about the Comp.std.c
mailing list