1

I was working with sockets , and i noted that a lot of the code i wrote repeated in different programs , so i wrote functions for most of the stuff that i did and saved them in a ".c" file without a main function. I then included that file in all the programs that i wrote using #include . I thought of creating a header file for the same just to figure out how they work but i can't figure out what difference it would make. Won't it work the same way ?

Tabish Imran
  • 417
  • 5
  • 15
  • 2
    Sure, just compile your whole program as a single translation unit binding all with `#include`. Welcome to the 1960ies! Please read about software development and modular programming basics. – too honest for this site Feb 06 '16 at 15:19

1 Answers1

2

Including the .c files means the compiler has to preprocess, parse, and compile that code every time - even if it never changes.

Turning the common code into a library with a header file for the clients means it only needs to be compiled once.

This won't make much difference for a tiny amount of code, but it's a big deal for larger libraries.

nobody
  • 19,814
  • 17
  • 56
  • 77