Site Sections => About Us | Consultancy | Training | Software | Publications | Open Source | Support | Open Standards | FAQ | Jobs
Site Style Info

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

The C Book

This book is published as a matter of historical interest. Please read the copyright and disclaimer information.

GBdirect Ltd provides up-to-date training and consultancy in C, Embedded C, C++ and a wide range of other subjects based on open standards if you happen to be interested.


West Yorkshire Office

GBdirect Ltd
Bradford Design Exchange
34 Peckover Street
BRADFORD
BD1 5BD
West Yorkshire
United Kingdom

consulting@gbdirect.co.uk

Training: 0800 651 0338
General: +44 (0)870 200 7273
Finance: +44 (0)1353 615 174

Please call between 0900 and 1700 (UK time) on Monday to Friday


South East Regional Office

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

consulting@gbdirect.co.uk

Training: 0800 651 0338
General: +44 (0)870 200 7273
Finance: +44 (0)1353 615 174

Please call between 0900 and 1700 (UK time) on Monday to Friday


Please note:
Non-training enquiries should be directed, initially, to our UK national office in Bradford (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.