toggle quoted messageShow quoted text
Create a project header file and place the function prototypes in there. I have the header file from my CAT project for the QCX xcvr attached so you can see how I organized such a header file. My organization isn't etched in stone, but it's served me well over the years. Then at the top of each source code file, I have this preprocessor directive:
In the attached Doc.h header file, it starts out with:
// all the header file stuff...
with the closing #endif at the bottom of the header file. You can see how the data declarations are in the header file, but all globals are defined in the INO file. Data declarations are NOT the same as data definitions and programmers are horrible about treating them as though they are the same. Declarations create an attribute list for the variable and, in essence, the keyword extern tells the compiler: "This variable is defined in another file, but let me use it in this file as a [...attribute list]". I usually create the header file first, then move all of those data DECLARATIONS to the INO file, and use search-and-replace to remove the keyword extern from the declarations. Doing this means all variables are now defined when the INO file is compiled. A data definition also constructs that variable's attribute list, but also allocates storage for it in memory (i.e., it now has an lvalue). Using the header file as described above allows you to write code using the INO globally-defined variables in all cpp files that read in the header file using the #ifndef directive. It's the linker's responsibility to fill in all the lvalues during the compilation process.
Again...long answer to short question.
On Friday, June 5, 2020, 8:13:09 AM EDT, Dean Souleles <dsouleles@...> wrote:
Good advice. I had read that here on the board. I tried it and got compile errors. Every call from the .ino to a function in the .cpp throws a " not defined in this scope " error. Presumably, I need to add function prototypes to the h file. Or is there another way to make those functions visible to the main program? My cpp is a tad rusty so I will have to figure that out.
Thanks for looking it over. I appreciate it.