C: Why do we include header files, which declare but don't define?

后端 未结 5 585
迷失自我
迷失自我 2021-01-14 07:59

At a high level, I understand we use #include statements to make code from other files available to the current file. But I don\'t understand why we include a h

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-14 08:31

    Because if you include the header where there are definitions, in different .c files, you will have Multiple Definitions.

    The declaration is sufficient, because it allows the compiler to generate the calling code, after that the linker takes care of finding the definition and links the function call to the actual definition.

提交回复
热议问题