Suppose I wanted to use a function in my main() that is written in another file.
I have read that you have to uses headers then. I also want to use structures in my main and, in fact, the function needs a structure as an argument.
So in the beginning, I have to include the function header and define my structure:
When I write my function definition in another file, i.e. the header, the compiler also seems to need the structure definition. So I would write the structure definition again at the beginning of my header.
But this seems to be inefficient. Do I really have to specify my structure in both files?
No, if the structure is defined in the header file you won't need to define the structure in the source file just #include the header file in the file that needs to structure definition.
By the way main() should be defined to return an int: int main().
thank you, this makes sense! So in my main() file, the compiler will also compile the included headers first and then understand that there is no problem, if I use a struct that has been declared in the header?
@Manga
I don't have the code yet, only played around with this header stuff and thought about this 'problem'.