Friday, July 29, 2016

C Basics - Source Program in C

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."

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.

In source program, constants and macros are often organized into separate files called "include files" or "header files" that can be referenced in source files as required.

Preprocessor Directive:
A "directive" instructs the C preprocessor to perform a specific action on the text of the program before compilation.

Pragma:
A "pragma" instructs the compiler to perform a particular action at compile time. Pragmas vary from compiler to compiler. For example, you can use the optimize pragma to set the optimizations to perform on your program.

Declaration and Definition:
A "declaration" establishes an association between a particular variable, function, or type and its attributes. A declaration also specifies where and when an identifier can be accessed.

A "definition" of a variable establishes the same associations as a declaration but also causes storage to be allocated for the variable.

Function Declaration and Definition:
Function prototypes establish the name of the function, its return type, and the type and number of its formal parameters. A function definition includes the function body.

Both function and variable declarations can appear inside or outside a function definition. Any declaration within a function definition is said to appear at the "internal" or "local" level. A declaration outside all function definitions is said to appear at the "external," "global," or "file scope" level. Variable definitions, like declarations, can appear at the internal level (within a function definition) or at the external level (outside all function definitions). Function definitions always occur at the external level.

Blocks:
A sequence of declarations, definitions, and statements enclosed within curly braces ({ }) is called a "block." There are two types of blocks in C. The "compound statement," a statement composed of one or more statements, is one type of block. The other, the "function definition," consists of a compound statement (the body of the function) plus the function's associated "header" (the function name, return type, and formal parameters). A block within other blocks is said to be "nested."



Related topics:
Intro of C   |   Overview of C   |   Features of C   |   Applications of C   |   The Setup for C   |   Program Startup and Termination in C   |   Program Structure in C   |   First Program in C   |   Must Know Terms in C

List of topics: C Programming

No comments:

Post a Comment