Reputation: 4114
I am currently programming a µC in C, and for making things easier to read I separated all different connection functions (like SPI, TWI, GPIO) in separate function-/include-files. Thus I have now two files for all functions regarding TWI, two files for GPIO aso.. Now I want to use functions for SPI in my GPIO-functions, and the other way round. The easiest way would be to put simply all functions in a big file, but I want to avoid that in order to increase readibility. But I also can not include the GPIO-include file into the SPI-include file, after I want to use the functions from both files in the other file, too.
Thus, what is the best way to cross-use functions from two different files in C?
Upvotes: 0
Views: 45
Reputation: 46323
How to use headers:
int DoA();
int DoA2();
#include <b.h>
int DoA()
{
return 1 + DoB();
}
int DoA2()
{
return 2;
}
int DoB();
#include <a.h>
int DoB()
{
return 1 + DoA2();
}
And with safe guards, you'd do:
#ifndef _INCL_A
#define _INCL_A
int DoA();
int DoA2();
#endif
Upvotes: 2