Hi, can someone give me a good explanation of how source and header files work. Can I use function on one source file from another source file? any good links on this? I'm a lost and helpless VB programmer.
Thanks
Hi, can someone give me a good explanation of how source and header files work. Can I use function on one source file from another source file? any good links on this? I'm a lost and helpless VB programmer.
Thanks
Header files and source files are a convention, not an absolute.
In practice, header files are typically used to specify the information that is needed to make use of a set of functions (eg how to call the functions, what constant values are passed to functions, structures that need to be populated so they can be passed to functions, etc). Source files tend to include header files, and implement functionality (e.g. call functions that are declared in headers).
When you're building a non-trivial program, you will find that you have a number of header files, and those header files will be #include'd in three places
1) In other header files (eg to use functions in header A you need information on types that are described in header B, so header A #include's header B)
2) In source files that make use of the information in the header file (eg uses constant values, uses data types, calls functions) but the compiler does not visibility of how the individual functions are really implemented to be able to call them. An example is the standard library: to do basic I/O you will #include <stdio.h>, but you do not need to know how (say) the fopen() function is implemented - you just need to use it.
3) In source files that implement the functions that are specified in a header file. These source files #include a header file for functions they implement (eg header A specifies the mechanism by which a function is called, and source A #include's header A and then implements the function). These source files will typically include other header files that are needed to implement the required behaviours.
THe basic requirements are fairly simple. When a program is built, nothing is allowed to be defined more than once. If the linker sees two bodies for one function (presumably in different object files) it will tend to complain fairly bitterly about things like duplicated symbols. For this reason, the content of header files are usually (mostly) declarations (eg typedefs and function prototypes) while source files are mostly definitions (eg the bodies of functions).
In practice, the three classes I've described above are a little arbitrary, and overlaps can occur. For example, macros are often actually implementation details, and may be placed in header files.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You cant use a header file from a C program in a VB program, if thats what you mean.Originally Posted by gtriarhos