Is it a good practice to include all files in one .h file and include that file everywhere for AVR?

StackOverflow https://stackoverflow.com/questions/7285476

  •  19-01-2021
  •  | 
  •  

Question

Can I do like this

/*includeAll.h*/

#ifndef INCLUDEALL_H_
#define INCLUDEALL_H_ 1

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include "DataTypeDefs.h"

#include "timer_api.h"
#include "uart_api.h"
#include "RTC_PCF8563.h" 
#include "TWI_Master.h"
#include "ADC_LTC1859.h"
#include "spi.h"
#include "AT45DB161D_UART_AS_mSPI.h"

#include "Utilities.h"

#ifndef F_CPU 
#define F_CPU 16000000UL
#endif

#include <util/delay.h>


#include <string.h>

#endif /* INCLUDEALL_H_ */

And include this includeAll.h file everywhere. Everywhere means in all the project files.

Similar macro like #define INCLUDEALL_H_ 1 has been used in all the other files.

I see that in compile time it takes very long.

Was it helpful?

Solution

Aside from the compile time penalty, doing so makes changing/porting/refactoring of the code a lot harder.

I have the general rule that I keep dependencies at an absolute minimum. It doesn't take much work to include a missing header in the right place, and saves you a lot of headache later.

OTHER TIPS

You can user your includeAll.h as a precompiled header. I would recommend changing the extension to .pch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top