I just read through the tutorial on modularizing C code, but there are a few things in my program not mentioned in the tutorial, nor can I find them specifically in "The C Programming Handbook".
I am trying to break my program apart by grouping functions perform certain operations within the program, for example the function which I use to control a gearbox are all in a source file called GearboxControl.c, all the functions that take in user inputs are in a source file called UserInputs.c etc...I also at this point have only a single header file as my program is big enough to break apart but not big enough to need multiple header files at the moment.
My problem is the following: the main while loop (Main.c) contains
while( 1 ){ TriggerFlag = Fire( TriggerFlag ); TriggerFlag = Stop_Firing( TriggerFlag ); Run_Gearbox_Control( MagazineSize ); }
TriggerFlag and MagazineSize are defined within the scope of main (which of course main is located in the source file Main.c).
All function prototype declarations are located in Main.h
bool Fire( bool TriggerFlag ); bool Stop_Firing( bool TriggerFlag ); void Run_Gearbox_Control( uint8_t MagazineSize ); uint8_t Set_Magazine_Size( uint8_t MagazineSize ); void Set_Motor_Speed(void); void Run_In_Safe_Mode(void); void Initialize(void);
The function definitions for Fire and Stop_Firing are located in GearboxControl.c, which has the proper include files for io, interrupts and main.h ect..
I am getting the following two errors:
../Main.h:45: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Fire'
../Main.h:46: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Stop_Firing'
What exactly is going on? At first I was thinking that I needed to declare Fire and Stop_Firing (GearboxControl.c) as extern because they are returning TriggerFlag which is defined within the scope of Main, but passed into and out of both functions. However MagazineSize is defined within the scope of main as well as passed into and out of Set_Magazine_Size(UserInputs.c) and there are no compile errors present with that functions.
The only difference is that TriggerFlag is called TF within the scope of Fire and Stop_Firing, which I don't think should make any difference since is pass by value. Thanks for you help in advance.