About GBdirect Consultancy Training Development

Section navigation

Leeds Office (National HQ)

GBdirect Ltd
Leeds Innovation Centre
103 Clarendon Road
LEEDS
LS2 9DF
West Yorkshire
United Kingdom

consulting@gbdirect.co.uk

tel: +44 (0)870 200 7273
Sales: 0800 651 0338

South East Regional Office

GBdirect Ltd
18 Lynn Rd
ELY
CB6 1DA
Cambridgeshire
United Kingdom

consulting@gbdirect.co.uk

tel: +44 (0)870 200 7273
Sales: 0800 651 0338

Please note: Initial enquiries should always be directed to our UK national office in Leeds (West Yorkshire), even if the enquiry concerns services delivered in London or South/East England. Clients in London and the South East will typically be handled by staff working in the London or Cambridge areas.

4.5. Summary

With the appropriate declarations, you can have names that are visible throughout the program or limited to a single file or limited to a single function, as appropriate.

Here are the combinations of the use of the keywords, the types of declarations and the resulting linkage:

Declaration Keyword Resulting Linkage Accessibility Note
external none external entire program 2
external extern external entire program 2
external static internal a single file 2
internal none none a single function
internal extern external entire program 1
internal static none a single function 2
Although the accessibility of internal declarations prefixed with extern is program-wide, watch out for the scope of the name.
External (or internal static) objects are initialized once only, at program start-up. The absence of explicit initialization is taken to be a default initialization of zero.
Table 4.2. Summary of Linkage

There are a few golden rules for the use of functions that are worth re-stating too.

  • To use a function returning other than int, a declaration or definition must be in scope.
  • Do not return from a function by falling out of its body unless its type is void.

A declaration of the types of arguments that a function takes is not mandatory, but it is extremely strongly recommended.

Functions taking a variable number of arguments can be written portably if you use the methods described in Section 9.9.

Functions are the cornerstone of C. Of all the changes to the language, the Standard has had by far its most obvious effect by introducing function prototypes. This change has won widespread approval throughout the user community and should help to produce a substantial improvement in reliability of C programs, as well as opening the possibility of optimization by compilers in areas previously closed to them.

The use of call-by-value is sometimes surprising to people who have used languages that prefer a different mechanism, but at least the C approach is the ‘safest’ most of the time.

The attempts by the Standard to remove ambiguity in the scope and meaning of declarations are interesting, but frankly have explored an obscure region which rarely caused any difficulties in practice.

From the beginner's point of view, it is important to learn thoroughly everything discussed in this chapter, perhaps with the exception of the linkage rules. They can be deferred for a more leisurely inspection at some later time.

Footnotes

1. Stroustrup B. (1991). The C++ Programming Language 2nd edn. Reading, MA: Addison-Wesley