When the compiler sees add(3, 4)
it needs to know what that means. With the forward declaration you basically tell the compiler that add
is a function that takes two ints and returns an int. This is important information for the compiler becaus it needs to put 4 and 5 in the correct representation onto the stack and needs to know what type the thing returned by add is.
At that time, the compiler is not worried about the actual implementation of add
, ie where it is (or if there is even one) and if it compiles. That comes into view later, after compiling the source files when the linker is invoked.