Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C header generator

Name: Anonymous 2009-12-04 2:02

Is there a program to generate header files for C source files? I'm really fucking sick of writing header files. I'd like to just write .c files and have the .h files generated automatically when I type make from whatever source files I changed. These would be generated simply by copying struct definitions and function prototypes into the header (and disabling duplicate definitions by wrapping them in a disabled preproc).

This seems like it could be fairly simple. I'm building a library, so functions (and structs) that need to be in header files are generally annotated with visibility information (e.g. LIB_EXPORT). I could add another annotation (e.g. LIB_INTERNAL) which has hidden visibility but still goes into the header file. Or I could just copy all prototypes into the header file (nothing private, but no need to tag anything).

The top of the .c file could have includes separated in two sections, like this:

#if GENERATING_HEADER
#include <stdio>
#include "someheader.h"
#else
#include "myownheader.h"
#endif


Includes under the GENERATING_HEADER block would copied to the top of the header file, and this preproc would always be false during compilation. This would force you to declare your include ordering properly.

The generator could also copy doxygen-style documentation comments into the header files. This would make the include files sufficient documentation of function parameters without requiring the original source.

I don't think this would negatively impact compile time much if at all. Only when public functions are added to .c files would the appropriate header change, just as if I were updating them manually. I'm unconcerned with other header file considerations such as function inlining, although an inline function could easily be included in a disabled preproc that copies it to the header; this means inlines could be easily toggled on and off without moving code around, allowing you to easily test various choices on function inlining. I also don't give two shits about sepples compatibility (although it seems to me that template definitions could benefit greatly from this).

I'm pretty sure I could pull this off in a few hundred lines of Python. I've written similar tools before, and I haven't found anything online that does this. What does /prog/ think? Will this work, or am I wasting valuable time that could be spent writing header files?

Name: Anonymous 2010-05-20 13:02

WARNING NECRO THREAD

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List