Xref: utzoo comp.lang.c:12376 comp.std.c:351 Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!tut.cis.ohio-state.edu!bloom-beacon!mcgill-vision!odyssee!zap!mosart!onfcanim!vedge!lai From: lai@vedge.UUCP (David Lai) Newsgroups: comp.lang.c,comp.std.c Subject: Re: Calling functions by address Keywords: functions calling Message-ID: <795@vedge.UUCP> Date: 31 Aug 88 22:01:20 GMT References: <679@mssx.UUCP> Reply-To: lai@vedge.UUCP (David Lai) Organization: Visual Edge Software, St. Laurent, PQ Lines: 46 In article <679@mssx.UUCP> src@mssx.UUCP (Pleschutznig Andreas) writes: >Suppose following: > >We want to write a software emulation for another processor on UNIX >So we thought of doing that job by declaring the addresses of the emulation >routines and jumping to the routines by address like this > > (*addressarray[code]); > >I know, I know that *does not* work, but maybe there is someone knowing to >get around. You're missing the function call parenthesis: (*addressarray[code])(); the example below works, and is approx what you want to do (besides out news wont let me send the above unless I have more new text): typedef int (*ptr_to_int_returning_func)(); /* declares a type for readability */ extern int printf(), fprintf(), scanf(), strlen(); ptr_to_int_returning_func array_of_func_ptrs[]= { printf, fprintf, scanf, strlen }; /* get the idea? */ main() { /* lets do a few calls */ int i; i = (*array_of_func_ptrs[3])("test_strlen"); (*array_of_func_ptrs[0])("size was %d\n",i); /* test printf */ } I hope the example helps with the nasty syntax. -- "What is a DJ if he can't scratch?" - Uncle Jamms Army The views expressed are those of the author, and not of Visual Edge, nor Usenet. David Lai (vedge!lai@larry.mcrcim.mcgill.edu || ...watmath!onfcanim!vedge!lai) -- "What is a DJ if he can't scratch?" - Uncle Jamms Army The views expressed are those of the author, and not of Visual Edge, nor Usenet. David Lai (vedge!lai@larry.mcrcim.mcgill.edu || ...watmath!onfcanim!vedge!lai)