Joined: 16 Oct 2006 Posts: 110 Location: HOVE, EAST SUSSEX
How do i make header files
Posted: Sat Dec 02, 2006 4:39 pm
Hi All
Could someone be kind enough to explain how i can make my own
headed files like ( #include <myfunctions.h> )
for all my functions
So i can include it to my projects
Regards _________________ BOB_Santana
ferrumvir
Joined: 01 Feb 2006 Posts: 64 Location: England
Posted: Sat Dec 02, 2006 5:22 pm
Open a new file in a text editor and save it with '.h' extension. Write your routines in the file just as you would normally. Then use the #include statment to include the file in your source.
The #inlcude statment is a compiler directive and tell the compiler to replace the #inlucde statement with the contents from the file. The comiler compiles as if those routines were in written directly in the file.
There is a another thing you can do with header files, but I've not seen it used with PICs. It's used heavily in larger (PC based) projects.
The header file includes function declarations, this requires a second source file comtaining all the functions '.c' Both the main c file and this c file include the header, and are compiled separately, creating to object files '.o.. The linker (one of the later stages of the compilation process links routines from the two object files together.
In large projects this can be used to encapsulate sections of the code. The inferface between code sections is the header file. The sections can then be modified knowing that it will not affect another part of the application, and becomes very reusable.
I've not yet managed to do this for my PIC programming because each program tends to use taylored algorithims.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum