hey! include files!

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Tim

Re:hey! include files!

Post by Tim »

OK, my turn to flame:

IF YOUR KERNEL BECOMES LARGER AS A RESULT OF USING HEADER FILES, YOU ARE DOING IT WRONG.

A header file contains *only* function and variable declarations.

A simple header file: (the right way)

Code: Select all

void *malloc(size_t bytes);
void free(void *ptr);
extern int errno;
Then you'd implement malloc and free in one (and only one) source file, and provide a definition for errno (without extern) in one (and only one) source file. Then you'd link together all the source files.

There should be absolutely *no* change in size as a result of doing this.

However, there *will* be a change in size if you put the function and variable *definitions* in header files. This is because all the functions are being included in your kernel as many times as they are used. This is WRONG.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:hey! include files!

Post by Pype.Clicker »

the only reason i can envision why linking code makes it bigger than including it is that in the case of linked code, the compiler can't tell in advance if it can use near (4 bytes offset) or short (1 byte offset) calls for functions that are in other modules. However, as the scope of a short call is +/-128 bytes only, there are little chance that a kernel can benefit of this situation ...
Post Reply