Re: [OT] What is a 'header' file?
- Posted by Derek Parnell <ddparnell at big?o?d.com> Jun 04, 2008
- 769 views
ZNorQ wrote: > > I'm not quite sure what a header file is. Header files are used by the C and C++ languages. They generally contain definitions that are used by a C/C++ program. Specifically they contain definitions of routines but without the actual details of the routines' implementation, just the name, return type, and parameter signature. For example... int foo(char *, int); This says that there is a routine called 'foo' that returns an 'int' and accepts as parameters a pointer to a 'char' and an 'int', declared somewhere else. The compiler uses this information so that when it comes across a call to the routine, it can validate the parameters on the call, and how the return value is handled. It can do this before it eventually comes across the actual routine's implementation details. A header file might also contain struct and class definitions, but again it doesn;t have to have implementation details, just the layout of the data items in them. eg. class Bar { int abc; char* ddd; float xyz; } Then, when the compiler comes across a reference to an object of the class 'Bar', it knows enough to check that the reference is valid. Header files are useful for single pass compilers because it means that it can deal easily with forward references. Header files are not needed for multiple pass compilers. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell