Specifying linkage

In the previous example, the function is defined in the same source file, so there is internal linkage. If the function is defined in another file, the prototype will have external linkage and so the prototype will have to be defined like this:

    extern int mult(int, int);        // defined in another file

The extern keyword is one of many specifiers that you can add to a function declaration, and in the previous chapters we have seen others. For example, the static specifier can be used on a prototype to indicate that the function has internal linkage and the name can only be used in the current source file. In the preceding example, it is appropriate to mark the function as static in the prototype.

 static int mult(int, int); ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.