About header files



Hi,

I have some questions about header files:

Say I have a file functions.c which contains a couple of functions. I have declared some structs in this file too. The structs are defined in main.c. Now I create a header file which represents the interface of functions.c to my main program file main.c.
I put in the header file: all function prototypes with keyword extern and the declarations of the structs, which are defined in the main program.

Do I include the header file functions.h in my file functions.c to get the struct declarations or do I explicitely declare the structs in functions.c and not include the header file?

About standard libraries: functions.c uses stdio.h, stdlib.h and string.h. Thus, I include the header files. main.c also uses stdlib.c and stdio.h. Do I include them again or do I use inclusion guards to check if they are already included (e.g. in functions.c)?

If a variable is declared static, is it still legal to pass it on as a function argument to a function outside of the file? In my case I have declared a struct in my file functions.c, "exported" it via functions.h to main.c and defined a variable with it as static. main.c calls a function from functions.c using this statically defined variable. It works, but why? Isnt the scope of the variable limited to main.c?

The keyword extern in front of a function prototype in my header file says that the function is defined somewhere else, right? Do I HAVE to declare the function prototype as extern in the header file? If I remove the extern my program still compiles flawlessly.

Thanks,
Chris
.



Relevant Pages

  • HIDE 1.0.7 now available for HLA
    ... which uses the wscan.exe program to extract windows constants and external declarations from the w.hhf header file to create a more compact version to include in programs. ... This is an early experimental version which requires some manual work to get all the symbols referenced indireclty through the windows header file. ... -option to auto-complete common HLA structure keywords -1 click/key jump to declarations -debug mode and debug window to display output. ...
    (alt.lang.asm)
  • Re: Header files question
    ... keyword) in a header file which you include where needed. ... So Nils, what you are saying? ... Declarations in the header file? ... You have a fundamental misapprehension in your usage of header ...
    (comp.lang.c)
  • Re: <Help> Simple Pause Needed.
    ... In a 'real' program you might put the declarations ... in a header file ... copy-paste is a nice easy way to do the forward declaration. ... Let's see (from Borland online help): ...
    (comp.lang.cpp)
  • Re: Suppose: All code in header files?
    ... > in the source file not in the header file. ... the only includes that should be in a header file are those ... If you're making declarations or function prototypes in your implementation ... The purpose of the header file is to declare the interface to the ...
    (comp.lang.cpp)
  • Re: multiple file programs
    ... "Francis Glassborow" wrote in message ... >>What is a header file, ... > A file containing mainly declarations of functions and definitions of ... > Needed by the linker for a GUI program. ...
    (alt.comp.lang.learn.c-cpp)