So I heard the #include directive in C/C++ can include virtually any text file, whether it be .h, .c, .txt, etc. Is it good to include the .c/.cpp sources in your files instead of the headers?
so my main.c will consist solely of #include's, #define's, and #pragma's and other weird directives (possible macros, etc)... and I will have an my_algorithms.c, a my_data.c (which will #include some .txt files itself), and my_game.c which will be the game engine.
Or is this the WRONG way to build a large program? :(
While it is allowed to include the .c files in a #include statement, it is considered bad practice. It can be useful for certain performance related code, it can become make maintenance of the code difficult in the long run.
Also this can cause builds to fail because many environements assume that each .c file will create one object file. This can lead to you having problems linking.
It's legal but has all kinds of problems. For example, static variables or functions in one of the source files (statics are supposed to be known only in the scope of the file that they're declard in) are sudddenly known throughout your entire program. There are other examples of why this is bad. It'll also lead to enormous build times. Change one thing in one of the files, the preprocessor will include them all into one big file and you're essentially always doing a full rebuilt. So long story short, yes - this is absolutely the wrong way. :P
Join our real-time social learning platform and learn together with your friends!