Some programs are structured this way.
A typical example is SQLite . It is sometimes compiled as amalgamation (executed at build time from many source files).
But this approach has pros and cons.
Obviously, compilation time will increase quite a lot. So this is practical only if you rarely compile this material.
Perhaps the compiler can optimize a bit. But when optimizing the connection time (for example, using the recent GCC, compiling and communicating with gcc -flto -O2 ) you can get the same effect (of course, by increasing the build time).
I do not need to write a header file for each function
This is the wrong approach (having one header file for each function). For a project with one person (less than one hundred thousand lines of code, otherwise KLOC = kilogram code ), it is quite reasonable - at least for small projects - to have one common header file (which you could precompile if you use GCC ), which will contain declarations of all public functions and types and, possibly, definitions of static inline functions (small enough and called often enough to profit from inlining ). For example, the sash shell is organized this way (as well as the lout formatter , with 52 KLOC).
Perhaps you also have several header files, and perhaps there is some single "grouping" header, which #include -s all of them (and which you can precompile). See, for example, jansson (in fact, there is one common header file) and GTK (which has many internal headers, but most applications using it have only one #include <gtk/gtk.h> , which in turn includes all internal headers). On the opposite side, POSIX has a large number of header files, and it documents which ones should be included and in what order.
Some people prefer to have many header files (and some even prefer to put one function declaration in their own header). I do not (for personal projects or small projects in which only two or three people will code), but it is a matter of taste . By the way, when a project grows a lot, it often happens that the set of header files (and translation units) changes significantly. Look also at REDIS (it has 139 .h header files and 214 .c files, i.e. translation units totaling 126 KLOC).
The presence of one or more translation units also depends on taste (and convenience, habits and conventions). My preference is to have source files (i.e. translation units) that are not too small, typically several thousand lines each, and often have (for a small project less than 60 KLOC) a common single header file. Do not forget to use the build automation tool, for example GNU make (often with parallel build through make -j , then you will have several compilation processes running at the same time). The advantage of organizing the source file this way is that compilation is fast enough. BTW, in some cases it is advisable to use metaprogramming : some of your (internal headers or translation units) C "source" files can (for example, some scripts in AWK , some specialized C programs, such as bison or your own thing).
Remember that C was designed in the 1970s, for computers that are much smaller and slower than your favorite laptop today (as a rule, at that time there was no more than a megabyte or even several hundred kilobytes in memory, and the computer was, by at least a thousand times slower than your mobile phone today).
I highly recommend exploring the source code and building some existing free software projects (for example, on GitHub or SourceForge or your favorite Linux distribution). You will learn that they are different approaches. Remember that in conventions and habits, C is of great importance in practice , so there are various ways to organize your project in .c and .h files . Read about => nofollow noreferrer β.
It also means that I donβt need to include standard libraries in every file I create.
You include header files, not libraries (but you must link libraries). But you can include them in each .c file (and many projects do this), or you can include them in one header and precompile this header, or you can have a dozen headers and include them after the system headers in each compilation unit. YMMV. Note that on modern computers, the preprocessing time is fast (at least when you ask the compiler optimizer to optimize, since optimization takes longer than parsing and preprocessing).
Note that what goes into some #include -d file is normal (and not defined by the C specification). Some programs have some code in some such file (which then should not be called a "header", but just an "included file" and which should not have the suffix .h , but something like .inc ). Look at the example on XPM files. On the other hand, you could basically not have any of your own header files (you still need the header files from the implementation, for example <stdio.h> or <dlfcn.h> from your POSIX system), and copy and paste duplicated code in their .c -eg files have the string int foo(void); in every .c file, but this is very bad practice and disapproving. However, some programs generate C files that share common content.
BTW, C or C ++ 14 do not have modules (e.g. OCaml). In other words, in C, a module is mainly a convention.
(note that having many thousands of very small .h and .c files in just a few tens of lines, everyone can drastically reduce the build time, having hundreds of files of several hundred lines each is more reasonable in terms of build time.)
If you start working on a project with one person in C, I would suggest that you first have one header file (and precompile it) and several translation units .c . In practice, you will modify .c files much more often than .h . If you have more than 10 KLOCs, you can reorganize this into multiple header files. Such refactoring is difficult to design, but easy to do (just copy and paste the code). Other people would have different suggestions and tips (and this is normal!). But be sure to include all warnings and debugging information when compiling (so compile with gcc -Wall -g , maybe set CFLAGS= -Wall -g in the Makefile ). Use the gdb debugger (and valgrind ...). Ask for optimization ( -O2 ) when you are comparing an already debugged program. Also use a version control system such as Git .
On the contrary, if you are developing a larger project that several people would work on, it would be better to have several files - even several header files - (intuitively, each file has one person responsible for it, others make an insignificant contribution to this file).
In the comment add:
I'm talking about writing code in many different files, but using Makefiles to concatenate them
I do not understand why this would be useful (except in very strange cases). It is much better (and very common and common practice) to compile each translation unit (for example, each .c file) into its own object file (a .o ELF file in Linux) and link them later. This is easy with make (in practice, when you change only one .c file, for example, to fix the error, only this file compiles and the incremental build is very fast), and you can ask it to compile the object files in parallel with make -j (and then your build goes very fast on your multi-core processor).