Handmade Network»Forums
34 posts
C with auto generated headers

Has anyone tried this? What do you think?

https://hackaday.com/2021/11/08/linux-fu-automatic-header-file-generation/

I've been programming this way for a while. I just put everything in .h files and include them in a stack. The problem I am starting to run into, is when two things need to know about each other,and I have to do forward declarations which is a pain. I want to code like they do in the modern languages, so I don't have to worry about that kind of thing.

This is small and mature. Why don't they put it in C?

https://fossil-scm.org/home/doc/trunk/tools/makeheaders.html

https://fossil-scm.org/home/file/tools/makeheaders.c

161 posts / 1 project
C with auto generated headers

You can use the C subset of C++20, which does the same thing without generating headers to begin with. This is faster by exporting the functions into a compiled module, like an object file but including header information, instead of copy-pasting headers with quadratic complexity. There are however still cases where one would want headers for the sake of documentation and external linking.

https://en.cppreference.com/w/cpp/language/modules

I'm still waiting for the feature to mature before considering it for new projects.

34 posts
C with auto generated headers
Edited by Shastic on

I've been testing it, and it looks like it won't be of any use to me. It doesn't see macros I am using to make generic structs and functions.

34 posts
C with auto generated headers
Edited by Shastic on
Replying to Dawoodoz (#26342)

"You can use the C subset of C++20"

I saw a couple of people on Casey's Twitter complain that everyone uses their own subset of C++, and because C++ is so big, they don't understand the code their co-workers produce. So perhaps a good feature for any new or current language, would be a way to deal with that.

...

I've copied Casey's method of including all .h files with structs in them before the .c files, and it has made it easier.

Perhaps a third file type with function prototypes in it, included between the .h and .c include groups would make it even easier.

161 posts / 1 project
C with auto generated headers
Replying to Shastic (#26349)

Could also make a text editor grouping headers and source files together, so that the header is shown at the top of a combined document. Then no dependency on code generators.