Search code examples
cheader-filesfunction-declaration

Why include header in the method definition file?


say you have a source file named sum.c that looks like this:

#include "sum.h"

int sum(int x, int y) {
    return x+y;
}

What's the point of including method's header in it's own definition file? Aren't you supposed to include it only in source files that call the sum function?


Solution

  • This way you avoid possible problems if the definitions in the header and in the source files differ.