using header files
using header files
I was just wonder if its considered bad practice to have one header file for many source files. For example, Im working on my memory manager, and I decided I want top break it down into peices. One piece that handles virtual addresses, and another that handles physical. However, both of these components are part of the same memory manager, and I was considering putting all the function declarations in mm.h, even though all the functions wont be in the same source file. Im just trying to avoid having such a growing number of header files, when if Im working with the memory manager, I should be able to include mm.h, instead of paging.h, frame_allocator.h, etc etc.
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: using header files
It's best to have one header file per source, but if you use ifndef, define, endif statements around your headers, you could include all the paging.h, stack.h, etc. in a header file called mm.h and then use that.
Re: using header files
No they are not -- not if you break it down to smaller components. While the components might work together for a bigger interface, they are both very different interfaces and abstractions. i.e., you have a physical memory manager and a virtual memory manager on top of that. Collectively this can be coinsidered a memory manager; but it is two managers not one.For example, Im working on my memory manager, and I decided I want top break it down into peices. One piece that handles virtual addresses, and another that handles physical. However, both of these components are part of the same memory manager
If a component contains multiple source files, it is fine to put all of the function declarations in the same header file. However, keep in mind that header files should only expose the interface of the component. If they do not, then the header file should be part of the implementation, which is where the one header per source file rule comes in. If it is part of the implementation, but still as a standard "master" include file, that is bad design (common.h-like header files should be avoided.)and I was considering putting all the function declarations in mm.h, even though all the functions wont be in the same source file.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}