Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

Source Files and Source Programs

A source program can be divided into one or more "source files," or "translation units." The input to the compiler is called a "translation unit."




translation-unit external-declaration




Overview of Declarations gives the syntax for the declaration nonterminal, and the Preprocessor Reference explains how the translation unit is processed.


See the introduction to C Language Syntax Summary, for an explanation of the ANSI syntax conventions.

The components of a translation unit are external declarations that include function definitions and identifier declarations. These declarations and definitions can be in source files, header files, libraries, and other files the program needs. You must compile each translation unit and link the resulting object files to make a program.

A C "source program" is a collection of directives, pragmas, declarations, definitions, statement blocks, and functions. To be valid components of a Microsoft C program, each must have the syntax described in this book, although they can appear in any order in the program (subject to the rules outlined throughout this book). However, the location of these components in a program does affect how variables and functions can be used in a program. (See Lifetime, Scope, Visibility, and Linkage for more information.)

Source files need not contain executable statements. For example, you may find it useful to place definitions of variables in one source file and then declare references to these variables in other source files that use them. This technique makes the definitions easy to find and update when necessary. For the same reason, constants and macros are often organized into separate files called "include files" or "header files" that can be referenced in source files as required. See the Preprocessor Reference for information about macros and include files.

See Also

Community Additions

© 2014 Microsoft. All rights reserved.