Path: utzoo!utgpu!watserv1!watmath!att!att!linac!uwm.edu!zaphod.mps.ohio-state.edu!rpi!uupsi!sunic!nuug!sigyn.idt.unit.no!ugle.unit.no!hanche From: hanche@imf.unit.no (Harald Hanche-Olsen) Newsgroups: comp.sys.mac.programmer Subject: Function pointers and lack of type conversion in Think C Message-ID: Date: 2 Nov 90 17:06:56 GMT Sender: news@ugle.unit.no Organization: The Norwegian Institute of Technology, Trondheim, Norway. Lines: 38 Executive summary: Bug in Think C -- If a function is called via a function pointer then automatic type conversion of its args does not take place. Consider the following file: ---------------- typedef void (*funpoint)(long, long); void fun_a(long,long); main() { funpoint fun; int i=1, j=2; fun=fun_a; (*fun)(i,j); fun_a(i,j); } void fun_a(long a, long b) { printf("fun_a: %08lx %08lx\n", a, b); } ---------------- This produces the two lines of output: fun_a: 00010002 00020001 <<== WRONG (int args are not converted to longs) fun_a: 00000001 00000002 <<== Right Think C has no excuse for this, as the fun pointer has a type that allows the compiler to determine the type of the arguments. This caused lots of interesting crashes for me, as I was porting a U**x program that likes to play with function pointers. Comments? - Harald Hanche-Olsen Division of Mathematical Sciences The Norwegian Institute of Technology N-7034 Trondheim, NORWAY