Program Structure; The Main Function And Program Execution; Name Spaces - Advantech UbiQ User Manual

Scenario manager
Table of Contents

Advertisement

Syntax
punctuator : one of
[ ] ( ) { } = ;
These characters have special meanings in C.
4.2

Program Structure

This section gives an overview of C programs and program execution. Terms and
features important to understanding C programs and components are also intro-
duced. Topics discussed include:

The main function and program execution

Name spaces

4.2.1
The main function and program execution
Every C program has a primary (main) function that must be named main. The main
function serves as the starting point for program execution. It usually controls pro-
gram execution by directing the calls to other functions in the program. A program
usually stops executing at the end of main, although it can terminate at other points in
the program for a variety of reasons. At times, perhaps when a certain error is
detected, you may want to force the termination of a program. To do so, use the
return keyword.
Functions within the source program perform one or more specific tasks. The main
function can call these functions to perform their respective tasks. When main calls
another function, it passes execution control to the function, so that execution begins
at the first statement in the function. A function returns control to main when a return
statement is executed or when the end of the function is reached.
You can declare any function, except for main(), to have parameters. The term
"parameter" or "formal parameter" refers to the identifier that receives a value passed
to a function. When one function calls another, the called function receives values for
its parameters from the calling function. These values are called "arguments".
4.2.2
Name spaces
The interpreter sets up "name spaces" to distinguish between the identifiers used for
different kinds of items. The names within each name space must be unique to avoid
conflict, but an identical name can appear in more than one name space. This means
that you can use the same identifier for two or more different items, provided that the
items are in different name spaces. The interpreter can resolve references based on
the syntactic context of the identifier in the program.
This list describes the name spaces used in C.
4.2.2.1
Functions of controllers
Function names are allocated in name spaces associated with each controller. That
is, the same identifier can be a component name in any number of controllers at the
same time. Definitions of component names always occur within controller's name.
Uses of component names always immediately follow the member-selection opera-
tors (.). The name of a function must be unique within the controller, but it does not
have to be distinct from other names in the program.
4.2.2.2
Ordinary identifiers
All other names fall into a name space that includes variables, functions (including
formal parameters and local variables), and enumeration constants. Identifier names
have nested visibility, so you can redefine them within blocks.
UbiQ Scenario Manager User Manual
44

Advertisement

Table of Contents
loading

Table of Contents