r/C_Programming • • Sep 12 '26

Question What C function would you delete and rewrite first, and why?

For me it's fnmatch - mostly because it's 40 year's old and smell's funny.

93 Upvotes

238 comments sorted by

View all comments

-3

u/jwzumwalt Sep 13 '26

I have not used header files since 1995. I have been programming in C for over 55 years. I avoid C headers files like the plague.

Every other programming language is able to operate just fine without them and in my opinion C should be no different. For large projects I do use a few include files if it contributes to clarity, but header files often make tracing a programs flow about as hard as trying to figure out what a object oriented program is doing. There is no reason that .h files (or at least whatever info they provide) can't be generated at compile time from the source itself.

In my opinion C headers where a product of experimentation. At the time C was written everything under the sun was being tried and experimented with. When you worked on a computer with 8K of memory it made sense to break things up into many files and directories. As I remember, Pascal was the next popular language and it (and all other languages) dropped headers. Headers are an experimental relic.

5

u/musbur Sep 13 '26

I don't understand. How is a translation unit supposed to know what the signature of a function in another translation unit is?

0

u/jwzumwalt Sep 13 '26

C is a single pass process. If another file is included at the top of the main program there is no disparity or confusion.

3

u/palapapa0201 Sep 13 '26

So you put everything into a single c file?

-1

u/jwzumwalt Sep 13 '26

As I mentioned it depends on clarity and the size of the project. How do all the other languages successfully exist without header files?

1

u/palapapa0201 Sep 14 '26

But you said you don't use any, which is impossible unless you put everything in a single c file

1

u/musbur Sep 14 '26

Nobody really understands what he means. It is true is that much (if not all) of the information contained in .h files is (or coule be made) available in the corresponding .c or compiled object files, and that having to keep .c and .h in sync can be bothersome. OTOH the .h file is also a good place to document the API which you need to do anyway.