User`s manual

Dynamic C Users Manual digi.com 51
Let’s say the above file is named mylibrary.lib. If an application has the statement
#use “mylibrary.lib” and then calls func_b(), will the printf statement be reached? The
answer is no. The order of compilation for module headers is sequential from the beginning of the file,
therefore, the macro SECONDHEADER is undefined when the first module header is parsed.
If an application #uses this library and then makes a call to func_a(), will that function’s print state-
ment be reached? The answer is yes. Since all the headers were compiled first, the macro
SECONDHEADER is defined when the first module body is compiled.
4.23.3 Important Notes
Remember that in a Dynamic C application there is only one file that contains main(). All other source
files used by the file that contains main() are regarded as library files. Each library must be included in a
LIB.DIR (or a user defined replacement for it). Although Dynamic C uses .LIB as the library extension,
you may use anything you like as long as the complete path is entered in your LIB.DIR file.
There is no way to define file scope variables in Dynamic C libraries.
/*** BeginHeader func_a */
int func_a();
#ifdef SECONDHEADER
#define XYZ
#endif
/*** EndHeader */
int func_a(){
#ifdef SECONDHEADER
printf ("I am function A.\n");
#endif
}
/*** BeginHeader func_b */
int func_b();
#define SECONDHEADER
/*** EndHeader */
#ifdef XYZ
#define FUNCTION_B
#endif
int func_b() {
#ifdef FUNCTION_B
printf ("I am function B.\n");
#endif
}