Alright, I understand how the extern definition works but I don't know what would be the "best" place to put them. Consider the following file structure:
- main.c / main.h / global.h
- drv_adc.c / drv_adc.h
- drv_pwm.c / drv_pwm.h
You might guess, this is quite common for a small microcontroller. The two drivers work on different parts of the hardware and have no interdependencies. Both drivers are able to set a flag (say: adc_irq_occured, pwm_irq_occured) which indicates something has happened and which will be handled in the main.c.
Now I can think of two approaches where I would put the "extern bool adc_irq_occured;" flag.
- The drv_adc.h: It somewhat belongs to the ADC driver, therefore I could add it to its header file and instantiate it in the main.c.
- I turn the logic around and place the extern declaration into my main.h (or global.h if it has to be so) and instantiate it in my drv_adc.c.
Now the question: Which option is the preferred option here? Is there any good book where I could read about such topics?