| 1 |
<HTML> |
| 2 |
|
| 3 |
<HEAD> |
| 4 |
<TITLE> ACEDB source code documentation: dynamic function calling </TITLE> |
| 5 |
|
| 6 |
<LINK rel=stylesheet type="text/css" |
| 7 |
href="./wdoc.css" |
| 8 |
title="Style sheet for wdoc developer documents"> |
| 9 |
|
| 10 |
</HEAD> |
| 11 |
|
| 12 |
<BODY> |
| 13 |
|
| 14 |
<H1>Dynamic function calls without linktime errors</H1> |
| 15 |
|
| 16 |
<H2><FONT color=red>*** THIS IS A SPEC, CODE ONLY EXISTS AS A PROTOTYPE ***</FONT></H1> |
| 17 |
|
| 18 |
<PRE> |
| 19 |
|
| 20 |
The messsage system allows attempts to call C functions which may |
| 21 |
not exist, without getting an error at link-time. |
| 22 |
|
| 23 |
Declare such functions as follows: |
| 24 |
|
| 25 |
#include "message.h" |
| 26 |
|
| 27 |
MESSAGERETURN myfunc(va_list args) |
| 28 |
{ |
| 29 |
|
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
and call like this: |
| 34 |
|
| 35 |
if (call("myfunc", arg1, arg2)) |
| 36 |
printf("call to myfunc succeeded"); |
| 37 |
else |
| 38 |
printf("myfunc doesn't exist"); |
| 39 |
|
| 40 |
|
| 41 |
Notes: |
| 42 |
|
| 43 |
1) call returns a BOOL, true for success, FALSE if function is non-existant. |
| 44 |
2) the return value from the called func is a dummy, and thrown away. |
| 45 |
If you want a return value pass in an address. |
| 46 |
3) This stuff is all done using smoke and mirrors in the makefile, |
| 47 |
it's pretty robust (I hope!) but the special function declarations are |
| 48 |
parsed by a sed script, not a general purpose parser, so don't mess with |
| 49 |
the form too much. In particular: |
| 50 |
put MESSAGERETURN at the start of a line, |
| 51 |
keep MESSAGERETURN and the function name on the same line, not |
| 52 |
|
| 53 |
MESSAGERETURN |
| 54 |
myfunc(va_list args) |
| 55 |
|
| 56 |
don't make function prototypes. |
| 57 |
|
| 58 |
MESSAGERETURN myfunc(va_list arg); |
| 59 |
|
| 60 |
or declare variables. |
| 61 |
|
| 62 |
MESSAGERETURN my_var; |
| 63 |
|
| 64 |
both of which are useless amd will confuse the system. |
| 65 |
|
| 66 |
4) Source files are pre-processed before looking for the MESSAGERETURN |
| 67 |
lines, so use of commenting out, macros, include files, and #ifdef around |
| 68 |
code is fine. |
| 69 |
|
| 70 |
5) See man stdarg for how to get at the arguments of the called function. |
| 71 |
|
| 72 |
6) There is an additional function, |
| 73 |
|
| 74 |
BOOL callExists(char *func) |
| 75 |
|
| 76 |
which returns true if call(func) would, but doesn't make the call. |
| 77 |
|
| 78 |
7) MESSAGERETURN functions whose name begins with "init" are |
| 79 |
called automatically just after the rest of acedb initialisation. |
| 80 |
This allows optional subssystems to be initialised without insertions |
| 81 |
into xacemain. If more than one such init function exists, the order |
| 82 |
in which they are called is undefined. init functions must still take |
| 83 |
a va_list argument, but its value will be junk. |
| 84 |
|
| 85 |
</PRE> |
| 86 |
|
| 87 |
</BODY> |
| 88 |
</HTML> |