Creating a C Library: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
The wiki doesn't have syntax highlighting for x86 as(1), and add .size for _start
Line 133:
== Repeated Declarations ==
 
The occasional poor design of the C standard library has lead to the requirement that some declarations must be repeated in multiple header files. Worse, if a header needs the FILE declaration from stdio.h, it is not allowed to include stdio.h because of the namespace polution. This leads to a multiple maintaince problem and can be dangerous if you update the declaration in one place and forget to do it in another. If you have a look at GNU libc's stdio.h header, you will discover a maze of #ifdefs and #define __need_FILE preprocessor magic that allows you to #define __need_FILE #include <stdio.h> and then get <em>only</em> the declaration of FILE. While this works, it is very ugly and grows horribly in complexity.
 
Another solution is to put the FILE in its own header <decl_FILE.H> with its own include guard. This is much cleaner and simpler to understand, but causes extra work for the preprocessor which can get comparably expensive if this is done for a lot of declarations. An alternative solution is to pre-preprocess the header files by writing a simple compiler that automatically finds these <decl_FILE.h> inclusions and inserts the contents into the header file. This tradetrades some build-time-complexity for maintainability and runtime performance.
 
== C++ Compatibility ==