aa5 Subj : Re: Library built but Not working To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Thu Oct 14 2004 06:52 pm dkat wrote: >I know globals are frowned upon but they really are necessary for ISR and >the buffers it uses. These must come from the main program. I believe that >this is where things are failing when I load the routines as a separate file >with the previous global variables now being treated as externals in the >Main program.... My problem is grasping where the scope of the variables >are and how I should be declaring them... Daq.h - - - - #define COUNTERS 2 #define TIMERS 2 #define MaxBSize (4*1024); extern int counter[COUNTERS]; extern int timer[TIMERS]; extern WORD buffer[2][MaxBSize]; /* Other function and variable definitions */ Daq.c - - - - #include "daq.h" int counter[COUNTERS]; int timer[TIMERS]; WORD buffer[2][MaxBSize]; /* Other code, and the ISR */ Program.c - - - - #include "daq.h" int main(void) { /* just use the variables. */ counter[0] = 15; return 0; } > I am pulling out all of my old >books but nothing really addresses when you are compiling routines outside >of your main code. I ended up declaring the buffer that holds the sound >file as a double pointer in main and as a fixed array in the library. >Perhaps this should be the other way around.... Whether it is in the library or in main is of no consequence. The choice is "Who is responsable for maintaining the size of the buffers?" If you put the buffers in Main, then every application has to define them. But if they belong to the library, then the application can't forget to create them. Drawback is that Main can't then define larger buffers. That is, unless you make the sizes dynamic with a call to an initialization routine: (Just a very rough sketch) long DaqBuffersize; /* global (main can see it) */ static long LocalBuffersize; /* module (only daq can see it) */ bool DaqInit( int bufferssize, int numberofbuffers ) { DaqBuffersize = buffersize *2; LocalBuffersize = buffersize; for( i=0; i