I am trying to understand arducopter code. I see there are several function and variable declared as ‘static’ and used across multiple pde files and without using header file. I have basic knowledge of c and i have a understanding that static functions or variable cannot be used outside file.
I would like to know how this can be done. Is there any spacial arrangement done in makefile to make it possible?
C++ static means only one data item for all instances of a class. And scope is also important. i.e. are you using in a c-way or a c++ way.
see en.cppreference.com/w/cpp/language/static as quick example I googled.
Let me show you example of what I am trying to understand.
A static object ‘g’ is declared here github.com/diydrones/ardupilot/ … r.pde#L199
this object ‘g’ is accessed in different files without any headers or declarations. for example here github.com/diydrones/ardupilot/ … ude.pde#L7
When I try to compile example for similar situation in c or in c++.
static int i = 15;
I get error in file b.cpp that ‘i’ is not declared in scope.
ArduCopter.pde in Arduino world is main.c is the real world. So anything declared there is global to all your code.
Ps: it’s good too read this arduino.cc/en/Hacking/BuildProcess as Arduino will creat prototypes required making programming less confusing for begineers