W
W
Warbler2015-08-06 22:44:59
Microcontrollers
Warbler, 2015-08-06 22:44:59

Where to store global variables of struct type?

I want to store all the data coming from the sensors in one place and combine them into a structure, but the fields of this structure will change in different files (each interface has its own functions), so where should I declare it? the question arose because I already tried to combine all the functions of one interface into a structure, for example

struct typeSSP{
 void (*initSSP1)();
 void (*sendSSP1)();
};

in SSP.h at the very end after function prototypes and in SSP.c to initialize it
struct typeSSP ssp = { ...};
and in the main file before main() write extern struct typeSSP ssp;
everything worked for the time being, until, for example, I had to access ssp in the file with the description of the timer interrupts and therefore include SSP.h, which the compiler began to complain about the multiple declaration, I don’t know how to fix this error.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MiiNiPaa, 2015-08-06
@MiiNiPaa

There is no need to declare or initialize anything in header files.
Move extern struct typeSSP ssp; to the header file, and the ssp declaration itself and its initialization in SSP.c

P
Philipp, 2015-08-07
@zoonman

https://en.wikipedia.org/wiki/Typedef

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question