C coding standards
Contents
1.
Issue status
2.
Introduction
3.
Documentation
3.1
FILE PROLOGUE
3.2
Function Prologue
4.
Naming Standards
4.1
5ss Switch Category Codes
4.2
5ss Switch Module Names
4.3
Source File Names
4.4
Identifiers
4.5
Unreference labels
5.
Code Maintainability
5.1
Expressions for Logic Control
5.2
Assignment STATEMENTS
5.3
Goto Statement
5.4
Loops
5.5
Switch Statement
5.6
Break and continue statements
5.7
THE '?:' Construct
5.8
Unions
5.9
Bit manipulation
5.10
Data Types
5.11
Source featuring
6.
Coding Techniques, Style, And Format
6.1
Function Definitions, Invocations, And Templates
6.1.1
Recommended Template Organization Scheme
6.2
Data Definitions and Declarations
6.3
Type Conversion
6.4
Variables and constants
6.5
Stack USAGE
6.6
Operand grouping
6.7
#includes
6.8
PreProcessor Conditionals
6.9
Macros
6.10
Comments
6.11
White Space
6.12
Code Layout
6.13
FILE and FUNCTION LAYOUT
6.14
Module Declaration File Layout
6.14.1
Identification section
6.14.2
Module Initialization Section
6.14.3
Product Declaration Section
6.14.4
Product Definition Section
7.
Some Programming Tips
8.
References
8.1
About the References
8.2
References
9.
Glossary
10.
Index
11.
Attachment - 5ss Category Codes
12.
Attachment 200 - File Suffixes
Issue Status (1100.1200.10.1)
Issue 1.0 - December 22, 1982
Issue 1.0 - The 5ss Switch® Is The First Switching Product
To Use the c language. Many People Were Involved in The Development:
People Who Were Experienced In C C codeing, People Who Had Software
Knowledge but no c experience, and people who had no previous
Software Experience. AS A Result, A Wide Variety of ProgrammingStyles Appear in The Software Product.
This Issue Was Prepared by The Following People:
M. T. Abdel-Moneim, A. J. BERANEK, M. D. Bratcher, D. F. Christian,
J. R. CRAY, C. P. Lawes, R. H. McCullough, P. V. Polli, S. R. Ringwood,
J. A. Rypka, J. R. Towne, Y. Winograd, N. A. Yates.
Issue 2.0 - July 24, 1986
Issue 2.0 of this Document Includes Corrections, Modularity
Changes, And some Terminology Revisions.
Issue 2.1 - June 15, 1988
Issue 2.1 of this Document Includes Changes Which
Advise 5ss Switch Software Program of The Fact That AT & T Source Code IS AT & T
Product Which is Distributed to Customers and Maintenance Personnel.
Standards for Source Code Comments Which Present a Professional And Courteous Image
To these People is et..........
THIS ISSUE WAS Prepared by E. G. Halline of The Switching Systems Quality
DEPARTMENT.
Issue 2.2 - June 25, 1990
Issue 2.2 of this Document Includes Changes Which bere suggested by IMRS
Written Against this Document. these Changes include The Use of a constant
Width Font for Examples, An Updated Index, And A Variety of Corrections.
This Issue Was Prepared by The International Code and Code Review Process Team
And edited by j. jay.
Issue 3.0 - June 1, 1991
Issue 3.0 of this document WAS prepared by the combined efforts of the
International Coding Process Team, The U.S. Coding Process Team,
And RepeseTatives of RTR.
2. Introduction (1100.1200.10.2)
The 5ss Switch Coding Standards Task Force Was Created
At the beginning of august 1982, consisting of members
From Several Software Development Areas.
The Charter of the Task Force Was To Develop
And Document Standards for Current and Future5ss Switch Code in Order To Promote Uniformity
And Improve Quality of The 5ss Switch Code.
This Document Contains the Task Force Recommended
Standards for the Following Areas:
Code Documentation
Naming Standards
Language Features and Data Types
Coding Techniques, Style and Format
Section 3 (Documentation) Covers The Information
That Should Be Given In File and Function ProLogues.
Section 4 (Naming Standards) Provides Rules for Tha
Choice of function and data names.
Section 5 (Language Features and Data Types) and
Section 6 (Coding Techniques, Style, And Format)
Cover The Use of c statements and data type
And Provide the Required Layout
Of the code.
The Language Features and Data Types Section
Is More Oriented Toward
WHAT
Parts of the c
Language SHOULD BE Used for the 5ss Switch Whereas
The Coding Techniques, Style, And Format Section Concentrates
More ON
HOW
The Statements SHOULD BE
Used.
To Conclude, Some Recommended Programming Tips Are
Given in section 7.
A major considration in the creation of the standards
Was to Ensure That The Individual Software Developer
Can becomfortable with therm.
In The Future, Required Standards Will Be Added,
Deleded or modified as more experience and better
Understanding is gained on the needs of the
5ss switch code and the needs of the 5ss switch
Code developers.
All 5ss Switch Software Programmers Must Conso
The Fact That Lucent Technologies Source Code Is A Lucent Technology Technologies Product Which IS
Distributed to Our Customers and Maintenance Personnel
To Assisting Programs of the switch and
In clear.
IT IS Thremely Important to Present a Courteous and Professional Image In CodeCommentary, Both to Lucent Technologies Developers and to these External readers.
This Document Applies To All CODO That Goes Out To The Customer.
AS OF ISSUE 3.0, THIS Document Represents RTR Code Development in
Addition to 5ss Switch Code Developments. Where a Difference EXISTS
Between Rtr and 5ss Switch Code, IT IS NOTED.
The Coding Examples Will Adhere To The Standards Specified in This document.
For Clarity, THE CATEGORY CODE (See Section 4) Used Will Be EX
(for example) Except When Clarifying a Detail That Pertains To Actual Naming
Standards. OtherWise, Examples That Reflect Existing Code Will Be Avoided.
WHEN a "good" Example Is Compared with a "bad" EXAMPLE, Each Will B
Noted with "good practice" and "bad phactice", respective.
For the Most Part, We Have Tried to Make The Examples Conform To The Examples Conform
STANDARD. The Examples Are Geneleally Simplified In Terms of Robustness,
Data Definition Specific Semantics, etc. for Brevity.
3. Documentation (1100.1200.10.3)
Every File (Source Or Header) Must Begin with A File Prologue and Every
Function Withnin A Source File Must Be Precededed by A Function
ProLogue.
Contents of a new file limited be enclosed within the Relevant Feature
Constructs. in adduion, the user must user the Same Feature Construction
To Feature Headers Files and The Related Text Files.
The Following Describe The Mandatory Formats of File and Function ProLogues.
The User May Add More Information To The ProLogues (for Example,
THE User May wish to describe how the functions in the file relate to the
Product in the file prologue) But Cannot Delete Information Which
Is Marked As "Required" .cms / ECMS Supporting Tools Provide The Means for Obtaining Names of
Software Developers Who WERE / Are Directly Responsible for
Modifications to the source file (s). Therefore developer Name
SHOULD NOT APPEAR IN The File OR Function ProLogue.
3.1 FILE PROLOGUE (1100.1200.10.3)
The Purpose of a File ProLogue is to identify the file. (Individual Function
Descriptions are Found in the function proLogues.)
/ *
* File: (required) The full pathname of the header file OR
* Source Code File (Relative to the $ Node), E.g .:
*
* UHDR /
*
*
* (xr) Head /
*
*
*
* Additional Information: (OPTIONAL) Any Information Which May BE USEful
* for the user, E.G. General Description of the
* Functions in the file as a whole, ETC.
* /
3.2 Function ProLogue (1100.1200.10.3)
The purpose of a function prologue is to provide useful information about
The function, I.E. The function's description, return value (s), and
Any additional information about using the function.
The Following Is The Minimal Information That Needs to Be Included Withnin
A Function ProLogue.
Each Subsystem May Have Additional Fields Which Are Considered
Necessary./*
* Name: (required) The name of the function.
*
* Abstract: (Required) One / Two Sentence Abstract of The
* function performed by the routine.
*
* Returns: (required) The value (s) returned by the function.
*
* If the return value is predefined in a header file,
* Then the name of the header file where there
* Value Can Be Found Should Be Given.
*
* If the function does not return a value, then
* 'void' is specified.
*
* If the function does not return control to the
* Calling routine, Then 'The Function Does Not Return'
* IS specified.
*
* Description: (Required) Multi-Line Description Giving A Global
* Picture of the function.
*
* Additional Information: (OPTIONAL) Any Information Which May BE USEful
* for the user, e.g. Information That May Affect
* The manner or environment in which the
* Function Should Be Used, Other Related Functions,
* Side Effects, WHETHER IT's Part of A Loadable Package,
* etc. Pitfalls, Warnings, Function Operation MAY
* Be added here or under separate subheading.
* /
4. Naming Standards (1100.1200.10.4)
Naming Conventions make Programs More Understeable by Making Them Easier
To read. They can also give information about the Nature of the Identifier
And Should Describe ITS Use. this Section Presents Standards for
Identifiers (Variables, Function Names, Stec.) and for source file and 5ss switch module names. Some Subsystems May Define
Additional Standards to Follow.
All Names Must Reflect High Standards of Professionalism and Good Taste.
4.1 5ss Switch Category Codes (1100.1200.10.4)
In 5ss Switch Code,
File Names, And some Identifiers, Contain A "Category Code",
Which is defined as flollows.
5ss Switch Software Is Divided INTO "Subsystems".
Associated with Each Subsystem Are One or more category Codes,
CONSISTING OF TO Letters. Many Category
Codes Have The Same Name as The Subsystem to Which They Belong (for instance,
Category Code Up for Subsystem "UP"), and some category
Codes are buying in more than one subsystem.
See attachment 100 for the list of category cots and
Their associated subsystems.
Note That A Few Category Codes Have Special, Restricted Uses.
4.2 5ESS SWITCH MODULE NAMES (1100.1200.10.4)
For Modularity Subsystems, The Module Name Cannot Exceed Nine Characters. IT
Must Consist of the Following:
A category code in Upper case letters.
4.3 Source File Names (1100.1200.10.4)
Due to UNIX AND ECMS RESTRICTIONS, A File Name Cannot Exceed 12 Characters.
IT Must Const of the Following:
A category code (in 5ss Switch Code Only) in Upper Case Letters.
A descriptive name, consisting of one or more limited letters,
Digits, and underscores.
A period.
A SUFFIX.
A List of Commonly Used Suffixes IS listed in Attachment 200.
In General, Source File Names SHOULD BE Descriptive of the Function (s)
Withnin the file.
IT IS Highly Recommended That Each Source File Have ONE ONE SOURCE
Function.
In Such a Case, The File Name Should Be The Same As The Function Name, Up to The First 10 Characters.
When More Than One Function Is Decland in a Source File, The Cost To Build
That Source File Using The "Source =" Option in the build command is
Increased.
Furthermore, The cost to generate an inspection package with what That
Source File In It Increases Since The Entire File IS Printed, Not Just The
Changed function.
Thase Benefits SHOULD BE CAREFULLY ConsideRed When Adding A Second / Subsequent
Function to a source file.
4.4 Identifier (1100.1200.10.4)
Identifier Should Be Short, Yet Meaningful.
With Compilers That Do Not Support "flexnames",
Only the night ele hracters of the name.
This Means That All Identifiers Must Be Unique Within The First Eight Characters
For the compiler to recognize the as different.
Identifiers Cannot Match A C Language Keyword OR AN M4 Keyword.
This Causes Lint Warnings (Even IF M4 Is Not Used on The File).
Users of the m4 and nm4 macro processors shouth
Aware That Sests Implicitly Define a set of macros.
THESE Macros Differ from Those Usually Defined by 5ss (R)
Switch Software Header Files In That They Are In All Lower
Case Letters ('Index' Is An Example of One of the Implicitly
Defined M4 Macros). Thus, Care Must Be Take To Avoid Defining
Variables with the Same name as these macros. The use of 'index'
as an identifier is a particularly Troublesome Occurrence.
The M4 Macro Preprocessor Will Replace All Occurrences of 'Index'
With (-1). this can basily be avoided by Adding Additional
Characters Before The Word 'Index', Such as Loop_index.
Alternative,
The Built-in Macros Can Be Und-in Macros Can Be Undefined Using The Built-Inm4 'undefine' macro. Users of M4 and NM4 Must Also Realize
That these macros processors do not by default us
Same Comment Delimiters as C. HoWever, The Comment Delimiters
Can Be Changed Using The Following Pair of Statements (EACH
START IN Column 1 of a line:
Changecom ()
Changecom (/ *, * /)
Pointer Variables Must end with "_ptr". Other Variables Must Not End
IN "_ptr". for example, a Pointer to A
Node
Structure Can Be
Named
Node_ptr
.
An Identifier Must Const of the Following:
A category code (in 5ss switch code only), When Required. The Table Below
Specifies When a category code is required.
A descriptive name, consisting of one or more letters,
Digits, and underscores.
The Following Table Shows The Naming Conventions for Identifiers.
Table 1. Naming Conventions
Identifier Type
Defined inside function
Defined Outside Any Function
Descriptive Name
Category Code
(5ss only)
Descriptive Name
#define (constant or macro), #undef
NOT Applicable
Upper case
Upper case
Other Preprocessor Defines
(# IF's, etc.)
NOT Applicable
None
Upper case
Typedef
UPPER CASE
Upper case
UPPER CASE
5ss Switch Struct / Union / Enum TAG
Upper case
Lower Case
UPPER CASE
RTR STRUCT / UNION / ENUM TAG
Lower Case
None
Lower Case
Struct / Union Member
Lower Case
None
Lower Case
ENUM MEMBER
Upper case
Upper case
Upper case
FUNCTION
NOT Applicable
Upper case
Lower Case
5ss variable
(Not Odd Global Parameters)
Lower Case
Upper case
Lower Case
RTR Variable
Lower Case
None
1st Letter Upper Case, REST LOWER CASE
5ss Switch Odd Global Parameters
NOT Applicable
GL
Lower Case
Labels
Lower Case
None
NOT Applicablenote The Following:
There is Some Macros Which Used To Be Functions, Ando Follow THE Naming
Rules for Functions (for Example, DBFRDTUP).
(5ss Switch Only for Enumerations Defined Outside Any Function, The Members' Category Codes
NEED NOT ALL BE Same or Match The Category Code of The Tag and
Typedef
.
In particular, "DM" is buy for the category code of domains
ENUM
s
Or Otherwise, But Never for the
ENUM
MEMBERS.
For Convenience of Using The Output of The "NM" Command (Namelist Command)
Which Prints Out Symbol Table Information, All Structures,
Unions, And Enumerations Should Be Given A Tag, Even IF The Also Have A
Typedef
.
THE
Typedef
, IF present, Must Be named the as the tag. if there
Is A Category Code (Outside a 5ss Function), The Category Code Must
Be Upper Case for THE
Typedef
And Lower Case for the Tag.
This, However, Does Not Apply for Structures Or Unions Which Occur With
Another structure or union.
In That Case, The Embedded Structures Or Unions MAY HAVE TAG OMIMIMIMTED.
The Below Example Illustrates THIS:
Typedef struct extrape {/ * tag nextary * /
Struct {/ * no tag nextary * /
EXTYPE1 TYPE1;
EXTYPE2 TYPE2;
} Type;
} EXTYPE;
4.5 Unreferenced Labels (1100.1200.10.4)
Unreferenced Labels Are Used by Developers in 5ss Switch Code So
Scripts Written for lab testing can reasoning the label instead
of a breakpoint number OR OR
To Force a Breakpoint Number At a Specific Line Of Code
That the Optimizer Had Removed.
Side-Effects from Using Unreference Labels Are:
Labels Force the Optimizer to Break The Code Into Smaller Blocks
WHERE The Next Optimized Block Starts at The Location of The Label.
INEFFICIENT CODE GENERATION AND A REAL TIME PerformanceDegradation Are The Result.
The Impact Will Depend On The Number of Labels in A Function
And the location of the labels in a function (I.E. Inside a loop).
Unreferenced Labels Clutter Code Making It More Difficult To Read
And understand.
IF Not Clearly Documented, Unreferenced Labels Confuse The Developer
As to their purpose (I.e Was IT INTENTIONALLY Placed in The Code
OR DID SOMEONE REMOVE THE
goto
But forgot the label?).
To Avoid these Undesirable Effects, The Following
Guidelines WERE Established for unreferenced labels.
Permanent Unreferenced Labels Are Labels That Will Remain in The
5ss Switch Code After Cutover.
Permanent Unreferenced Labels Are Allowed In Critical Functions Used by
Load Bringup to debug the bringup session.
Such Labels Should Be Clearly Marked With The Following Comments.
/ *
* Unreferenced label - Requester by loading bringup
* Label Will Remain Permanently in 5ss Switch Code.
* /
No more Thanling Labels Should Exist Withnin a critical function.
Non-critical functions sales never contain permanent unreferenced
Labels.
Permanent Labels Should Never Be Inserted in Real Time Critical Code.
Permanent Labels Should Not Appear in Loops.
Temporary Unreferenced Labels Are Labels Put in Code During The
Developer's testing stage to be removed at a later time or
NOT INCLUDEDIN The OFFICIAL Build of a Product.
All Temporary Unreferenced Labels Should Be Nonded with The
ApproPriate Comments.
/ *
* Unreferenced label
* Temporary Use by developer to set testing breakpoints.
* /
All Temporary Unreferenced Labels Should Be Inserted Between T
C-Preprocessor Flag, Debug, (Like So).
#ifdef debug
Label1:
#ENDIF
Since The Official Load Does Not Build with The Debug Flag Set, thislabel is not Built as part of the official loading.
When a developer Runs a private, (s) He Must Explicitly Set
The flag to use the label.
Also Note That The Official Load Will Fail
To build if a user inserts a
goto
For a Temporary Label That
IS PROPERLY
IFDEF
'ed.
No more Than Two Temporary Unreferenced Labels Should EXIST
ININ A FUNCTION.
Executing "NLINT" Will Warn The Developer About Every Label That
IS defined but not reasoned.
The "nlint" Listing SHOULD BE CHECKED
TO Ensure That Any Label Comment As Unreferenced Is Not
Reference.
5. Code Maintainability (1100.1200.10.5)
Code MaintainAbility As an Extension of Coding Standards DEALS
Issues Beyond Syntax. it addresses Issues with code complexity That
Make C Code Easier To Maintain. MAINTAINABILITY ISSUES DESCRIBED IN
Subsections 6.2 (Variables / Functions Per Line) and 6.5 (Stack Usage).
5.1 Expressions for Logic Control (1100.1200.10.5)
The Use of an Arithmetic Expression for logic control,
Where Zero Is Taken As False and Anything Else As True, IS Not ALLOWED.
INSTEAD,
An Explicit Comparison to Zero Must Be Made.
Bad Coding Practice:
IF (Charge_index)
{
/ * Charge the call * /
}
Good Coding Practice:
IF (Charge_index! = 0)
{
/ * Charge the call * /
}
5.2 Assignment Statements (1100.1200.10.5)
Embedded Assignments and Statements
WITH SIDE EFFECTS Are Not ALLOWED.
They area Harden to read,
Harden to debug,
The Order of Evaluation May Be Undefined,
And May Sometimes Create Unpredictable Results.
Bad Coding Practice:
/ *
* Embedding One Assignment Inside Another. * The Following Statement IS Diffult To Debug
* Because a Breakpoint Cannot Be set on The
* Assignment of the value of "yvar".
* /
XVAR = (YVAR = APARM BPARM) CVAL;
/ *
* Embedded Assignment.
* The Following Statement is Difficult to Debug
* Because a Breakpoint Cannot Be set on The
* Assignment of the value of "b_ptr".
* /
IF (a_ptr! = null && ((B_PTR = a_ptr-> next) -> value)! = 0)
{
EXFUNC (B_PTR-> VALUE);
}
Good Coding Practice:
Yvar = aparm bparm;
XVAR = YVAR CVAL;
/ * Good practice * /
IF (A_PTR! = NULL)
{
B_PTR = a_ptr-> next;
IF (B_PTR-> Value! = 0)
{
EXFUNC (B_PTR-> VALUE);
}
}
The Following Are Examples of An Assignment Statement
And an Embedded Assignment Statement
In which the order of evataly is undefined
And they is not allow.
Bad Coding Practice:
/ *
* The Point at Which "I" is incremented is compiler dependent.
* /
Array [i ] = i;
/ *
* The Point At Which The Array Index Is Evaluated IS
* Compiler Dependent. Consesequently, The Array Index
* Depends on an unknown value.
* /
Array [weight] = (weight = wparm);
Good Coding Practice:
Array [i] = i;
i ;
Good Coding Practice:
Weight = wparm;
"= weight;
5.3 Goto Statement (1100.1200.10.5)
User of the
goto
Statement is strongly discouraged.
THE
goto
Should Only Be Used When Absolutely Necessary
(for Example, To Go To a Single Error Processing Point Under Abnormal
Conditions or To Break Out of Several Levels of
Switch
,
for
,
And / OR
While
Nesting. WHEN USED,
all
goto
Statements Must Be Clearly CommentTedto Indicate The Change In Program Flow.
When considering the use of a
goto
STATEMENT,
One Should First Consider a Redesign of The Code
To Avoid The Use of A
goto
.
Section 3.9 of Reference [A] and Chapter 2 and 3 of 3 of
Reference [b] Have Good Discussions on the use
Of the
goto
Statement.
5.4 Loops (1100.1200.10.5)
CHANGING THE
for
Loop variable or Changing the
Terminating boundaries in the body of the loop shouth be avoided.
Termination of the loop should depend on a test involving
The loop variable.
Bad Coding Practice:
For (i = 0; i { IF (Condition == True) { / * Change loop variable * / i = 7; / * BAD PRACTICE * / } IF (Other_Condition == True) { / * Change Terminating Boundary * / MAX - = 2; / * BAD PRACTICE * / } } THE While and Do-while Constructs Are Better Choices for Complicated looping and where a change of the loop variable OR OR Terminating expression is required. The use of Break and Continue Statements is encouraged, Especially when Use of A goto IS Tempting. However, The Use of A Break oral Continue Statement Must Be Clearly Commented to Indicate The Change In Program Flow. This Is Particularly Important When Nesting Loops. 5.5 Switch Statement (1100.1200.10.5) THE Switch Statement is a Much Better Choice Than A Series Of ELSE-IF 's Test Different Discrete or Distinct Values Of The Same Variable. Conversely, A Series of ELSE-IF Statements is a much better choice tour a Switch When the execution of a leg of code is conditional on Ranges of values of the same variable. A Switch Statement Must Have Adefault Case. THE DEFAULT Case Must Be The Last Case In The Case List. In a Switch Construct, IF Falling Through is Necessary IT Must Be Clearly Commented. EVERY Case , incruding the DEFAULT , Must End with Either a Break STATEMENT, a Return STATEMENT, a Continue Statement (when in a loop, Or With A Comment Stating That Fall THROUGH IS EXPECTED WHEN THE Case Falls Into the next Case IF the Last Instruction in The Case Is a non-return function, a Break Statement Must Still Following The Function Call. 5.6 Break and Continue Statements (1100.1200.10.5) Any Break Statement not at the end of a Case Construct within a Switch Statement and all Continue Statements Must Be Clearly Commented. The Comment SHOULD INDICATE The Change in Program Flow. When in a loop, ATTEMPT to use the the Else Part of the IF Construct INSTEAD OF THE Break oral Continue Statement. However, Consider Program Readability And Use Additional Variables, When Necessary, To Control Program flow. QuestionAble Coding Practice: While (i { IF (Special_Case == True) { Continue; / * branch back to top of loop. * / } } Good Coding Practice: While (i { IF (Special_Case == True) { } Else { } } 5.7 The '?:' Construct (1100.1200.10.5) Except in macros, the ' ?: 'Construct Is Not ALLOWED For logic control. WHEN USED in in-line Source Code, The ' ?: 'Construct Be Can buy in Either An Assignment Statement, a Return STATEMENT, or when passing parameters to a caled function.when buy in a c macro, Nesting of the construct is left To The Discretion of the Programmer, Otherwise, The Must Not Be Nested. Bad Coding Practice: A_PTR = (Nitems == 0)? Malloc ( : Realloc (A_PTR, Good Coding Practice: IF (NItems == 0) { A_PTR = Malloc ( } Else { A_PTR = Realloc (PTR, } 5.8 Unions (1100.1200.10.5) When Using union S, It is the programer's responsibility to keep track Of which data type is currently store union . Among Other Things this Can Be Done by Defeing a Variable To Track The Last Data Type Stored in The Last Data Type union Al by Embedding THE union Withnin a structure and defining a member within The Same Structure Which Serves as a tag to track the Last Data Type Stored in The union . The Following Is An Example of The Second Alternative. The structure member "Type" Serves as a tag to TRACK The Last Data Type Stored in The Structure Member "Variant" Which is defined to becom union : / * Define the node type. * / Typedef enum exfacttype { Unary, Binary, Leaf, } ExNodetyPE; / * Define a node. * / Typedef struct exNode { ExNodetype Type; / * Variant Tag * / Union { Struct { / * Pointer to Left Node * / EXNODE * LEFT_PTR; } unary; Struct { / * Pointer to Left Node * / EXNODE * LEFT_PTR; / * Pointer to Right Node * / EXNODE * RIGHT_PTR; } binary; Struct { Short info; / * Leaf data * / LEAF; Variant; } ExNode; 5.9 Bit Manipulation (1100.1200.10.5) Bit Fields Offer The Capability Of Defining And Accessing Adjacent Bits Withnin A Word Directly, Rather Than Bitwise and Shift Operators (See Section 10.6.4). Although Bit Fields Provide Direct Access, Bit Manipulation Using Bitwise and Shift Operators May Be more conducive for looping. Consider The Following Example Which Packs A Sequence of 4-bit BCD Digits Into a Single 32-Bit Word: / * Define bit Field size of bcd digit. * / #define bfbcddig 4 Value = 0; For (i = 0; i { Value | = (STR [I] - '0') << ((NUMDIG - I - 1) * bfbcddig); } Almost Everything About Bit Fields Is Implementation Dependent. For example, They is assigned left to right on some machines and right to leave On On Others. Consesequently, Although Bit Fields Are Useful For Maintaining Internal-Defined Data, The Question of Which End Comes First Must Be Carefully Considered When DEALING WIXTERLY-Defined Data. Programs That Depend On Such Details Are Not Portable. The underlying data type of a bit field shouth be each esthar An Appropriate ENUM Type or an unsigned TYPE. The size of a bit Field Should Be a #define CONSTANT 5ss only). Consider the folowing example in which a process id is packed INTO AN Unsigned long Data Type. The process ID is Made Up of Three Values: A Process Number, a Processor ID, And a uniqueness value. Bad Coding Practice: / * Define Masks for Components Of Process ID. * / #define exmsk_procno 0xffff #define exmsk_pcrid 0xff #define exmsk_uniq 0xff / * Define Bit Offsets for Components Of Process ID. * / #define EXLSB_PROCNO 0 #define EXLSB_PCRID 16 #define EXLSB_UNIQ 24 / * BAD PRACTICE * / / * Extract components of process ID. * / Procno = (Procid >> EXLSB_PROCNO) & Exmsk_Procno; PCRID = (Procid >> EXLSB_PCRID) & exmsk_pcrid; UNIQ = (Procid >> EXLSB_UNIQ) & exmsk_uniq; Good Coding Practice: / * Define bit Field SIZES * / #define bfprocno 16 #define bfpcrid 8 #define bfuniq 8 Typedef struct exprocid { Unsigned long procno: bfProcno; Unsigned long PCRID: BFPCRID; UNSIGNED Long Uniq: bfuniq; } Exprocid; EXPROCID PROCID; Good Coding Practice: / * Extract components of process ID. * / Procno = procid.procno; PCRID = procid.pcrid; UNIQ = procid.uniq; 5.10 DATA TYPES (1100.1200.10.5) Data Types Should Be Chosen to Give An Accurate Description Of the data being defined. Two Logically Similar Items Should Use the Same Typedef . Two Logically DiffERENT ITEMS SHOULD USE DIFFERENT Typedef S, Even if They has the Same Range of values. ENUM S Should Be Used to Define Values Whose logical meanings are more important tour The Actual Numbers Used to Represent Them. For Example, The Logical Value of A Signal, WHETHER IT IS onHOOK, OFFHOOK OR FLASH, Is More Important Than The Actual Numbers Which represent these values. 5.11 Source Featuring (1100.1200.10.5) Source featuring is a component of the extended Change Management System (ECMS) That permits the definition and maintenance of Different, Concurrent Versions of Source Files within The Same Ecms Generic Release. It is buy Isolate and maintain (in a given software release) functionality That IS Required by some software refreases and not by tahers. For Example, Featuring Can Be buy isolate Functionality Between Software Release 5E4 (2) and 5ee3. Feature Names Are Defined (by The ECMS Administrator) in The ECMS RELATION GPF For Each ECMS Generic and Project. It is the developer's responibility TO BE AWARE OF THE VALID FEATURES TO USE ON Which Source Files and to understandthe impacts of usding featuring. Refer to the ECMS User's Manual for A More Detailed Discussion of Featuring, ITS USE, And ITS Impact on software development. Implementation Restrictions Are listed here: Feature Lines, Including Any Continuation of the Expression, Must Be Less Than Or Equal to 512 Characters. THE #feature and #ndfeature Constructs Must Begin in Column 1. The Exclusion of Source Code May Be Done with Either "Not" OR "!" In The EXPRESSION. For Consistency, Use Whichever Method Is Currently in The Source Code. Use existing #feature Statements Rather Than Introducing More Featuring When THE MR Adding The ORIGINAL Featuring Construction Has Not Been Added To your target loading yet. Reusing featuring constructs add by mrs which area not yet approved CAN Lead to dendencies. If you cannot Accept the dependency, One May Add Additional Featuring Statements to Avoid Any Mr dependencies. THE FOLLOWING IS An Example of Featuring and The Extracted Code for Both Feature "a" and feature "b" Versions. Editable Version / * Common code. * / a b c #feature (a) / * Code for feature a only. * / x x x #ndfeature (a) / * More Common code. * / di e fly #feature (b) / * Code for feature b Only. * / G hide i #ndfeature (b) / * YET MORE Common Code. * / j k l Extracted Versions Feature a Version Feature B Version / * Common code. * / / * Common code. * / a a a B B c c / * Code for feature a only. * / / * More common code. * / X DX E x f / * More Common code. * / / * Code for feature b Only * / D g e h f / * YET more Common code. * / / * Yet more common code. * / J J K K L L The Following Illustrate The Correct and IncorRect Methods Of adding code 'b' for the software rectection supporting Feature C: Bad Coding Practice: / * Common code * / #feature (c) a #ndfeature (c) #feature (c) b #ndfeature (c) / * More Common code * / Good Coding Practice: / * Common code * / #feature (c) a b #ndfeature (c) / * More Common code * / 6. Coding Techniques, Style, And Format (1100.1200.10.6) 6.1 Function Definitions, Invocations, And Templates (1100.1200.10.6) A "Function Template" Refers to a Function Declaration That Also Contains Argument and return type information. Function Templates Are Contained in Template Header Files That (when Included) Enable The Compiler To Verify That Actual Function Calls agree with the Template in Type and Number of Arguments. The purpose of this "type-checking" is to catch ceertin function interface Faults Between Programs as Early as Possible. Function Templating Saves The Effort of Manually Finding and Fixing Function Interface Faults at some increased Expense in Liding Costs. Also, Function Templating is a more automatic and reliable way of catching Function Interface Faults Than Manual Inspection Or Testing. a cost / benefit Analysis of function Templating Indicates That The Savings in Finding Andfixing Faults Meets or Exceeds The Increased Expense In Liding Cost (For more details, see the cost / benefit analysis in 112000 / v1100 / 10 / 1200.t). Function Templates Must Be Implement by All Subsystems. All Functions Must Have A Function Template. This Coding Standard Applies NOT Only to New Code But Also To EXISTING CODE. The Long-Term Goal IS To Be Able To Compile with the Option That INDICES THAT A FUNCTION IS CALED WITHOUT A TEMPLATE BEING Defined. (adding usr_cflags = "- warn, templates" to THE MODBUILD Command Line Will Cause The Compiler To Warn of Missing Templates For Both Defined and Reference Functions.) Exceptions are allowed Only by consSensus within a subsystem if the templating Causes Extraordinary Resource Demans. Exceptions by a subsystem must be flly Document and maintained Under CMS Control in a File. this file must contain details on Differences of Naming Conventions, Conformance for New Functionality, And Other Details of What THE Web Must do when adding or modify or using old / new functions. this comments File Would Be Accessible To All Developers and Would Explain Any of The Subsystem's Templating Exceptions, Naming Variances, AS Well As Differences Between Releases (E.G., Between u.s. and international releases). This Templating Coding Standard Applies To All Subsystems, Promotes CommONAlity Between The U.S. and INTERNATIONAL PRODUCTS, And Allows Flexibility. Subsystems Must Follow Thase Standards as The Add New Code or As The Modify EXISTING CODE. Subsystems May Grandfather EXISTING TEMPLATING Schemes; Otherwise, The Must Use The T-File Organization Scheme Described BELOW.TEMPLATES MUST BE OF THE FORM ... [exTern | static] return_type func (arg1_type, arg2_type, ..., argn_type); For example: Extern ExretVal EXFUNC (Exshort, EXLONG *); Declares That The Function EXFUNC RETURNS A VALUE OF TYPE EXRETVAL AND Takes Exactly Two Parameters: An Exfire. A function template or declaration shouth be precededed by a Linkage Specifier, Either Extern oral Static . A Static Linkage Specifier Can Only BE Used In a Template Header File Of Module Scope. Any Function Template Or Declaration Without a Linkage Specifier IS Extern By Default. Functions Must Be defined WITH EXPLICIT RETURN TYPES. IF A Function Does Not Return A Value, The Type Void Should be used. Defaulting to an an Implicit Return Type of int Is not permitted. A Function Template IS Always A Function Declaration Butt Declaration is not necessarily a function template. E.G. Extern Void EXFUNC (VOID); <- Template and Declaration EXTERN VOID EXFUNC (); <- Declaration ONLY THE TEMPLATE DECLARES THAT FUNCTION EXFUNC DOES Not Return A Value And That it expects no parameters. The Void In The Parameter List Must Be Used in this Instance, Otherwise the Compiler Will See The Template As a Declaration Only And Will NOT WARN IF A Parameter IS passed. The use of ellipses (...) to disable the checking for arguments Should Be Used Only In Special Cases When Necessary. Function Templates Should Be Organized Into Template Header Files That Have Three Logical Levels of Scope As Follows: Global (UHDR / SS): Functions Called Outside of The Subsystem. Subsystem (SS / HDR): Functions Called Local To The Subsystem.Module: Functions Called Local To The Module. Functions Should Be Scoped At The Lowest Level Possible To Prevent Unnecessary Dependencies and rebuilds. The Scheme Described Below Is The Recommended Way To Organize Function Templates at all scopes, and is the default scheme for globally scope Templates. WHERE POSSIBLE, SUBSYSTEMS SHOULD IMPLEMENT A Common Function Templating Scheme for All Releases (E.G., A CommON IMPLEMENTATION for Both the u.s. and INTERNATIONAL PRODUCTS. IF a subsystem HAS Already CREATED FUNCTION TEMPLATE FILES USING A DIFFERENT Scheme, The Subsystem Can Keep The EXISTING NAMING CONVENTION AND Scheme and Document The Scheme in The In any Templating Scheme, Function Templates Should Be Logical Organized And Partitioned Into Multiple Template Header Files To Reduce The Number of REBUILDS WHEN Program Changes Are Made. If a subsystem has not yet create function template files, the subsystem Should Follow The Recommended Scheme. 6.1.1 Recommended Template Organization Scheme (1100.1200.10.6) A CommON Function Templating Organization Scheme Should Be IMPLEMENTED For All Releases (E.g., A CommON IMPLEMENTTION WITHIN A SUBSYSTEM for Both The u.s. and international product. To eat in Reusing code BetWeen T U.S. and International Products, Templating Code Should Be Added with Feature Construct Names That Are Not CBU Dependent. A Moducts (low-level objects). It is recommented That a subsystem's template header files be Organized so it its defined Function Templates Are Maintain ON Either A Module OR Product Basis, Dependingon The Design of The Individual Subsystem. The Product Basis, Described Below, Is The Most General Case, And Must Be Used WHEN A Module Builds Products That Use The Same Function Name Defined Differently Across these Products. For Many Subsystems That Do Not Have this Situation, Using The Module Basis To Organize Their Templates Is Sufficient and Will Reduce The Number of Template Header Files That Must Be Maintained. in The Descriptions Below, Substitution Module for PRODUCT and MOD for PROD TO Get The Module Basis Scheme. Each Low-Level Product Must Maintain Template Header Files Containing The Templates for All Functions Defined in That Product. EACH Product Will Have At Most Three Template Header Files Depending Upon The Scope Of where the functions are called. The Product's Template Header Files Should Be Organized and named As Follows: UHDR / Using the naming convention above, if Functions Are Built In To More Than A Single Product, THESE FUNCTIONS MUSTAIN More Than One Template, I. One per produter. The Templates Should Be Enclosed in #if STATEments to Separate Templates That Differ Across Different Selector Combinations, And to Make Maintenance Of Identical Templates Across Selectors Easier. If A Function is Scoped Differently For Different Selectors, E.G. Subsystem for Pam and Global for PSM, Maintain The Template Using The Higher (I.E. Global) Scope. . The Order of Header Files Will Help in Locating Extra INAPPRIATE Function Declarations. if a subsystem HAS ALREADY INCLUDED TEMPLATE HEADER Files in Their Module Declaration Files, The Subsystem Can Keep THEIR EXISTING ORDERING. For The Product Exprod in Module Exmod, The Header Files in The Uses List shop be maintained in this Order: Uses = / * in exprod, if any * / TEXPROD.H / * SUBSYSTEM Scope Functions Defined * / / * in exprod, if any * / ... / * Other Global and Subsystem Scpe * / ... / * Template Header Files for * / ... / * functions reasond by exprod * / ... / * All Non-Template Global and * / ... / * Subsystem Header Files * / ; The Header Files in The HEA HEADER List shop be maintained in this Order: HEADER = ... / * All Non-Template Module Header Files * / TEXPROD.H / * MODULE Scope Functions Defined in * / / * EXPROD, IF ANY * / ... / * Other Module Scope Template Headers * / ... / * for functions caled by exprod (i.e. * / ... / * functions defined in another esmod * / / * Product), if any * / ; All Data Types Reference by Function Templates Must Be Available At The Proper Scope. Global and Subsystem Scope Template Headers Must Contain The appropriate #include Directives for Any Data Types Reference In The Templates. for module scope template headers, Reference Data Types Must Be Made Visible To The Template Via Theheader oral Uses List in the module decaration File. Any Reference Data Types Declared in Source Files Must Be Moved Into A header file. IF a macro exissrs in a non-template header file for the purpose Of Hiding The Actual Function Being Called, The Function Template Should Precede the macro definition in The Non-Template Header File. this is an Exception to the Above Templating Organization Scheme. For Scoping Purposes, Fat Table Entry References To a Function Can Be ignored. Also, Fat Table Entries Do Not Have to Reference Function Templates; They May Continue To Use Function Declarations. this Is Because The Use of Osfap () TO Invoke A Function Forfeits the Capability TO Perform type-checking. Function Invocations Must Match Function Definitions and Templates In Number and Type of Parameters. In Other Words, The Arguments Passed To A Function Must Agree In Number and Type with the arguments defined for That Function. The Exception To this rule is functions That Have Templates That Allow for a variable number of parameters may use elipses (...). for esample, A Function That Requires At Least One Parameter, AN Exshort, But May Have More Parameters Would Have A Template of The Form: Extern ExretVal EXFUNC (Exshort, ...); When Passing Struct oral union Pointers as parameters, do not Define the body of the Struct oral union In The Function Definition Parameter List. Always use previously defined Struct oral union Types So That a Function Template Can Be provided. for example, Bad Coding Practice: Exretval EXMSGFUNC (MSG_PTR) Struct { EXMSGHEAD MSGHEAD; Exmsgtext text; } * msg_ptr; { ... } Good Coding Practice: Typedef struct exmessage {exmsghead msghead; Exmsgtext text; } Exmessage; / * Good practice in source file * / Exretval EXMSGFUNC (MSG_PTR) Exmessage * msg_ptr; { ... } 6.2 Data Definitions and Declarations (1100.1200.10.6) Function Declarations and Data Declarations with global scope (Across Source Files) Must Be supplied and Extern Edin Global, Local, or Module Header Files Provided by the Referenced Subsystems. Use a Module Header File for Scope Withnin A Module, A Local HEADER File for Scope Withnin A Subsystem, And A Global Header File for Scope Crossing Subsystem Boundaries. When Using Unions for OSDS Messages, Ensure the Union Contains Only Those Messages Which Are Expected (or a large majority of them). if The Union Contains Many Other Unnecessary Merses, Consider Creating Another Union Containing Only the Required Messages. Avoid Declaring Message Unions WITHIN A Function. THIS CAN LEAD to NUMEROUS Function Changes When Adding New Expected Messages. Choose Integral Data Types According to the Following Criteria: IF The Quantity Must Be of A Fixed Size (in An Inter-Processor Message, for example, use a type tres to a charr , Short OR a Long As Required. OtherWise, IF The Quantity May Exceed 16 Bits, Use a Type That Resolves TO A Long . Otherwise, IF The Quantity Has Storage Class Auto And Space Efficiency Is More Important Time Efficiency, Use a Type That Resolves TO A charr oral a Short . Otherwise, Use a type tria resolves to an an int . Initialization of Non-Constant Non-Static Local Variables Must Be done in the code segment rather Than at the point of definition. It is recommended That Only One Variable or Function Be Declared Per Line. this Enhances Readability, Provides the Opportunity for Bettercomment, and Makes Maintenance Easier if some variables or functions change Type. this is a recommendation rather Than a rule because it make ocquasionally Make Sense To Group Closely Related Variables That Act As Part of Larger Conceptual For example: Exshort Currow, Curcol; / * Current Screen Position * / When Declarations Are Not One-Per-Line, The Following Rules Apply. Don't Mix Variables and Functions With Same Declaration. Don't Mix Initialized and Uninitialized Variables within the Same Declaration. 6.3 Type Conversion (1100.1200.10.6) The Following Integral Promotions is Performed: Operands of Type charr oral Short Are Converted to Type int Promotion of charr TO int May Involve Zero-Padding OR SIGN EXTENSION, Depending on The Compiler. Promotion of Short TO int Is Always Done WITH SIGN EXTENSION. Operands of Type Unsigned char May Be Converted to Type int oral Unsigned int Depending on the compiler. Operands of Type Unsigned short Are Converted to Type Unsigned int . Bit Fields Are PROMOTED TO Either Signed Or Unsigned Quantities, Depending on the compiler and the size of the bit field. Given Two Operands with Promoted Types As Shown In The Left Column and Top Row Below, The Operands Undergo Arithmetic Conversion To The Type Shown In The Table, And The Result of The Operation Will Have The Same Type (See Section 6 of Reference [P]): With The Exception of The Values Null and 0, Use Type Casts for ALL Conversions Not listed Above Or That Are listed as being compiler depend. The Values Null and 0 Need Not Being Pass Unless They Are Being Pass as function call parameters.table 6.-2. Arithmetic Conversions int Long Uint Ulong int int Long Uint Ulong Long Long Long [u] long Ulong Uint Uint [u] long Uint Ulong Ulong Ulong Ulong Ulong Ulong WHERE uint Stands for Unsigned int And Ulong Stands for Unsigned long . THE [U] Long Entries May Be Either Long oral Unsigned long Depending on the compiler. Integral Types Undergo Arithmetic or Storage Conversion As Follows: If the Source And Destination Are The Same Size, The Bit Pattern IS unchanged. A Source IS Converted to a Smaller Destination by Truncating The High-Order Bits. An Unsigned Source Is Converted to a Larger Destination By ZERO-PADDING. A Signed Source IS Converted to a Larger Signed Destination By SIGN EXTENSION. A Signed Source IS Converted to a Larger Unsigned Destination By Zero-Padding or Sign Extension, Depending on The Compiler. 6.4 Variables and constants (1100.1200.10.6) Variables May Not Be Used for more Than One Purpose within Their Scopes, Except When Used Only As Loop Counters, Array Indices Or Return VALUES. Register Variables Can Be Freely Used to Obtain Real-Time Efficiency. However, They Cause A Minor Problem in Debugging 3B20 Programs Using Dart Because Only The Register Variables in The Currently Active Function Can Be Displayed. The Restriction Does Not Apply to Debugging MC68000 Program Using ITS Because The MC68000 Stack Design Is Different from That of the 3b20. Consideration Should Be Given to The Fact That Register Variables Less Than Four Bytes Will Increase Stack Space. This is Because Registers Used For Variables Are Saved on The Stack At Function Entry. for Example, IF A TWO-byte variable is registerized, two bytes will be wasted on the stack.for mc68000, Stack overflow Must Be Considered When Registerizing Variables. See Reference [q]. THE Called Function is responsole For The Saving and Restoring of All Registers. so The stack space Used for Registers Does Not Dend On WHETHER A FUNCTION CALLS Another Function. IT Will always be used. Some Compilers Will Automatically Registerize Variables based on usage. Definitions of Automatic Variables SHOULD BE Ordeering by size And Type Take Advantage Of Addressing Alignment Characteristics. Exceptions May Be Necessary for Asserts, Which Dump Only The First 180 Bytes of the Stack Frame. Constants That Have a Specific Meaning (E.G., Number of Line Units, Maximum Buffer Size, Number of Array Elements, etc.) Must Be Given A descriptive #define Name. The Exceptions To this rule area when the number 0 is buy to reference the first item in An Array, And The Use of 0 OR 1 As The Initial Or Final Value of a Counter. The Method of Initialization of Constants Depends on The Type Of constant to be initialized. The Following Types of Constants Are Distinguished: #define Constants: True Constants Which Are Defined Using #define . Local Constants: Local Variables Whose Values Remain Constant During the execution of their enclosing functions. Global Constants: Global Variables Whose Values Remain Constant For a particular load or installation. Local and global constants must be initialized at their definitions. All Variables Must Be Initialized Before Uses. 6.5 Stack USAGE (1100.1200.10.6) Various techniques can be used to minimize stack usage in order to prevent Stack Overflow Problems. Here Are Few Examples Which Can Help Minimize Stackusage. Declare All Local Variables from Largest to Smallst in size. Therefore, All Structures Should Be Decland First, Followed by Longs, Pointers, INTEGERS, SHORTS, AND THEN CHARACTERS OR Booleans, In That Order. this Will Compact The local declarations as much as possible on the stack. INSTEAD of DECLARING LARGE STRUCTURES in Very High Level Functions (Functions at the top of the stack), Declare Structures in .bss data if possible. When this Is Done, Care Must Be Used to Ensure That The Data Will Not Be Corrupted IF A Real Time Break Is Taken. The .bss Data Does NOT OCCUPY ANY Stack Space And Can Be Reference Much Like Global Parameters. USE UNIONS INSTEAD OF DECLARING MANY DIFFERENT STRUCTURES On The Stack. This Is Especially Useful for Relation Structures Being Placed On The Stack Which Are ONLY Used ONCE IN ORDER TO OBTAIN DATA TO Read Other RELATION LATER. for esample: Union { Struct rlbigrel1 rel1; Struct rlbigrel2 rel2; ALL_RELS; / * Some code Here. Initialize Key to relation. * / Ret = dbfrdtup (rlbigrel1, (char *) & (all_rels.rel1)); IF (RET! = Glsuccess) { / * Error Handling. * / Return; } / * Some more code POSSIBLY. * / All_rels.rel2.key = all_rels.rel1.store; Ret = dbfrdtup (rlbigrel2, (char *) & (all_rels.rel2); IF (RET! = Glsuccess) { / * Error Handling. * / Return; } In The Above Example, It May Be Necessary To Temporarily Store The VALUES Retrieved from The First Read Into Local Variables So That They Are Not Overwritten When the information is copied in osits t in t t the second The use is necessary, The Amount of Stackspace Required To Store Temporary Variables Which Are Needed in The Subsequent Reads Is Likey Less Than The Amount of Space Needed to Declare The Entire RELATION on the stack. Another Alternative, Similar To The Idea Above, IS To Add Extra Function Calls. In General, a Function Call Will Add to the Stack Space. However, Smart Use of Additional Functions CAN Actually Decrease Stack Space. A Function Which Has Many Declarations on Its Local Stack Can Be Modified TO Call Two or More Functions Which AccompLish THE Same Functionality As The Same Large Function, But Each Only Containing A Subset of The Local Declarations. This Has The Benefit of Moving Many of the Local Declarations To Lower Level Functions Which Will Be Popped Off The Stack When The isy. Therefore, Having One Large Function with Many Local Declarations Can Use More Stack Space Than Group of Functions Called By A Higher Level Function Which USE A Small Portion of the Large Function's Declarations. Declare variables as locally as possible. Instead of declaring All the local variables at the beginning of the function, Declare Some within Case Statements and if Statements. The Compiler Optimizes this Stack USAge, Treating these Similar to Unions. Below Are Two Examples of Such Stack Usage: EXAMPLE 1: Switch (value) { Case Value1: { Struct rlbigrel1 rel1; / * Use Bigrel1 * / } Break; Case Value2: { Struct rlbigrel2 rel2; / * Use bigrel2 * / } Break; DEFAULT: { Struct rlbigrel3 rel3; / * Use bigrel3 * / } Break; } EXAMPLE 2: IF (value == 0) { Struct rlbigrel1 rel1; / * Use Bigrel1 * / } else { Struct rlbigrel2 rel2; / * Use bigrel2 * / } 6.6 Operand Grouping (1100.1200.10.6) The Following Table Lists C Operator Associative and Precedency in Decreasing Order by Row: Table 6.-3. Operator Precedence, Associative, And Type Type Operator (s) Associative primary () [] ->. LEFT TO RIGHT Unary ! ~ - - (TYPE) * & Sizeof Right to Left MultiPlicative * /% LEFT TO RIGHT Additive - LEFT TO RIGHT Shift << >> LEFT TO RIGHT RELATIONAL <=>> = LEFT TO RIGHT Equality ==! = LEFT TO RIGHT Bitwise & LEFT TO RIGHT Bitwise ^ LEFT TO RIGHT Bitwise | LEFT TO RIGHT Logical &&&& LEFT TO RIGHT Logical || LEFT TO RIGHT Conditional ?: Right to Left Assignment = = - = ETC. Right to Left Comma , LEFT TO RIGHT The Relative Precedency of The Primary, Unary, Multiplicative, And Additive Operators Is Fairly Well Known, As Is The Relative Precedence of The Relational And Equality Operators to the logical Operators. Knowledge of other precedences Varies Quite a Bit from Person to Person and Should Thereree Be Made Clear THROUGH The use of perentheses. Use of perentheses to indeicate the intended Operator Associative '-' Operators and Factors Involving multiple '/' or '%' Operators is Recommended. Uses Use Conservative Judgement When Eliminating Redundant Parentheses To Increase The Readability Of Extremely Complex Expressions. for example: Bad Coding Practice: (((A B) C) D) / * inteention is clear; () s Just Add Clutter * / A B / C >> EXCONST / * Precedence Is Not ALWAYS Remembed * / A> b == c> D / * DITTO * / / * * Elimination of White Space to Indicate Precedence May Be * misleading. The Following Appears to Suggest * precedence of "/" over "*". White Space Must Not Be Used * to suggest precedence. * / A * B / C - D / * This is equivalent to (x & (exxmsk == 0)) && (Y & (exYmsk! = 0)) * / X & exxmsk == 0 && y & examplek! = 0 / * This is equivalent to (attrib & extall) | EXWIDE * / Attrib & Extall | EXWIDE Good Coding Practice: A B C D / * INTENTION IS CLEAR for () S * / / * * "/" HAS Higher Precedence Than " " by Mathematical Standard; * () s show precedence of " " and "/" over ">>" * / (A B / C) >> EXCONST (a> b) == (c> d) / * () s clarify precedence * / / * * () s show left to right associativity of equal-precedence "*" and "/"; * "*" AND "/" have higher precatednce "-" by Mathematical Standard * / (a * b) / c - d / * * Both of The Following Styles Are IN Common Use. The First Leaves NO * Questions about precedence; the second signally reduces code clutter. * / (X & Exxmsk) == 0) && ((Y & Exymsk) == 0) (x & exxmsk) == 0 && (Y & Exymsk) == 0 More Information About Operator Precedence Can Be Found In Section 2.12 of Reference [a]. 6.7 #includes (1100.1200.10.6) All Subsystem-local and global header files must #include Any Header Files Needed to Define Symbols Used in The Header File [1] . In The ModuLarity Environment, NO Module-local Header Files (I.e. Header Files Which End With OR .LH) OR Source Files May Contain #include Statements. Any Header Files That Sests Require Should Be Included in The Module Declarative File. 1. In the pre-modularity environment, Header Files Began with a #define WITH a unique name. Inclusion of Each Header File in Other Files Was Conditional On The Unique Name to Prevent Multiple Inclusion. This Technique Should No LONGER BE PRACTICED AS CURRENT Header File Processing Makes this Unnecessary. 6.8 Preprocessor Conditionals (1100.1200.10.6) Conditional PreProcessing (Using #if , #ifdef , #ifndef , #elif , #ELSE , and #ENDIF SHOULD BE Used with Great Care Since The CLUTTER THE Natural Flow of the Code. The Code.. FOLLOWING Are Restrictions / Suggestions on Their USE: Conditionals Should Only Be Used for Minor Differences Based On The Definition of a Flag. Major Difference Should Be Handled by Providing Separate functions. Conditional Changes Withnin A Function SHOULD BE LOCALIZED As Much As Possible and Not Scattered THROUGHOUT The Function. That IS, Any Decisions That Depend Upon The Conditional Expression SHOULD BE MADE INE Place if Possible. A Conditional Must Not Split or Interrupt The Flow of a Complete C Statement. For example: Bad Coding Practice: IF ( #ifdef bar || ( #ENDIF ) { / * Do Some Stuff * / } Good Coding Practice: #ifdef bar IF ( #ELSE IF ( #ENDIF { / * Do Some Stuff * / } This Approach Results in Increased Readability and Maintainability of Code. Do Not Sacrifice Clarity of Code to Save Typing Or Tiny Amounts OFMEMORY. 6.9 Macros (1100.1200.10.6) Macro Definition Syntax Rules: IF a Macro Definition Contains Several C Statements, Therements Must Be Put on Separate, Back-Slash Terminated Lines Enclosed by a Do-while (0) For example: Bad Coding Practice: #define exmacro () Good Coding Practice: #define exmacro () / DO / {/ } / / * Constantcondition * / / While (0) THE Do while (0) Causes the macro To Expand to a Single, Simple Statement Terminated by Exactly One Semicolon (Provided by the Invoker). This Format Prevents Problems with IF-Less Else (Caused by Two or More SEMICOLONS WHEN A Macro IS Expanded) and Else-Less IF (See the First EXAMPLE IN THIS INVOKED AS A Simple-Statement Body for ann IF-Else Statement. THE / * Constantcondition * / Prevents Lint Errors Due To The Fact That The Condition With WHILELOP IS A Constant Expression, Always Resulting in a false Indication. This String Must Not be omitted. if not buy, a Lint Error Will Be Generated, One for Each INVOCATION OF THE MACRO. Arguments to a Macro That Can Be C Expressions Must Be Preenthesized THROUGHOUT The Macro Definition. In Addition, Any Macro whose results is a C Expression Must Be Parenthesized in Its EntireTy IT Contains An Operator And is not of the form Sizeof ( Expr ). For example: Bad Coding Practice: #define eXCONST EXOTHER_CONST 1 #define exmax (x, y) x> y? x: y Good Coding Practice: #define eXCONST (exother_const 1) #define Exmax (x, y) ((x)> (y)) The Preentheses Are Necessary TO Ensure That The Intended Operator Precedence Holds Regardless of How The Macro IS Used, And Regardless of the Nature Of Expressions passed as arguments. Macro Readability and Maintainability Rules: Macro Nesting and Size Should Result In Maintainable Software. Very Large Macros and Macros That Call Other Macros THROUGH MANY Levels of Nesting Can Cause MaintainAbility Problems and Excessive Memory Usage. Excessively Nested Macros Can Make Code Less Readable and More Diffult To Maintain and Debug. minimize the levels of nesting and macro size to avoid these problems. IF a macro is large, consider making it Into a function. Macros Should Only Be Used to Make Code Easier To Read and / OR More flexible (When the extra flexibility is needed). In this example, Either of these Two definitions of a macro to increment A Variable Using MODULO ARITIC Might Be Used, Depending ON Efficiency Considances: / * increment x modulo m assuming 0 <= x #define exincmod (x, m) ((x) = ((x) 1)% (m)) oral / * increment x modulo m assuming 0 <= x #define evincmod (x, m) / DO / {/ IF ( (x) == (m)) / (x) = 0; / } / / * Constantcondition * / / While (0) Both of these Definitions Perform The Desired Operation, But The IMplementation Details and The Fact That One is an expression and the other is not is hidden. This next example showing to hide a minor, though Obscuring, Detail, Such As Embedded Structure Names: X_PTR-> name1.name2.name3.name4.name5.key = 0; Can Be More Clearly Written: #define evItem_key name1.name2.name3.name4.name5.keyx_ptr-> exiteM_key = 0; Macros Should Definitely NOT Hide Important Details, Significant Operations or Side Effects (especially changes in flow control). Consider Using Self-Description Names for Parameters in Function-Like Macros to make Complex Macros Or Macros with Many Parameters Easier To Understand. 6.10 Comments (1100.1200.10.6) Comments shop be added to source code to aid in the understanding Of the program or to provide a ready with any sales To Understand The Code. Misleading Comments Are Worse Than No Comments. Uses . The Following Rules. There Are Three Acceptable Comment Styles: Trailing Comments, Single-Line Comments, And Block Comments. Trailing Comments Are Short Comments That Appear At the end Of a line of code and describe That Single Line of Code. The text of the Comment shop be sepaper.com The '/ *' and '* /' delimiters by White Space. Trailing Comments Withnin A Block of Code Should Be Tabbed to Line Up with Each other. for example: Int argc; / * argument count * / Char * argv []; / * argument list * / IF a comment is too long to fit on the line it it describes, use the salesle-line Or block "Comment format. SINGLE-LINE Comments SHOULD BE Used for Comments That Describe A Single Line But Are Too Long To Fit As a Trailing Comment Or for Comments That Describe Multiple Lines But Will Fit On ONE. A Single-Line Comment Precedes The Code It Describes, and Should Be Indented to match the code. like trailing commerss, the text of single-line Comments shop be self-owned from the '/ *' and '* /' delimiters by White Space. For Example: / * Sort Temp Unique on The Second and Third Fields. * / Execl (Exec, Exsort, "-u", " 1", "-3", temp, "-o", temp, (char *) NULL); See T NLINT (1) MANUAL Page for a list of special SINGLE-LINE Comments Used to Modify The Behavior of NLINT. Block Comments Should Be Used for Any Comment That Will Not NOT Fit on one line. Do Not Stack Single-Line Comments. Visually, A Block Comment Looks like this: / * * This is a block comment. Note That the * Delimiters Are ON Lines by Themselves. * / All '*' in the block comment harve the Same Indentation. The Opening "/ *" May BE FOLLOWED by Comment Text or Followed by White Space. The closing "* /" APPEARS ON A LINE BY ITSELF. The Comment Appears Before The Code It Describes, And the opening delimiter '/ *' Should Be Indented to the Level of The Following Code. Each Non-Delimiting Line Must Begin with a Space, An Asterisk, And Another Space, as shown. The Following Uses of Comments Are Not Permitted: Do Not Include Information That Is Not to Be Released To Customers Or Other Persons Who May Have Been Grand Access To Source Code. Comments May Not Include Anyhes That Reflects Poorly on Lucent Technology Technologies / Comments May Not Contain Slang Expressions, Graffiti-Like Phrases, Non-Standard Acronyms, or Terminology That Unclear To Outside Readers. Personal Opinion or Commentary is not permitted. Do Not Repeat What Is Self-eviDent from the semantics. For EXAMPLE: Bad Coding Practice: i; / * increment i * / Comments Are Almost Always Called for in The Following Situations, But Do Not Put in Comments That Do Not Add Value. File Prolaogues at the beginning, and functionProLogues Before Each Function Definition (see section 100.10.2). A statement of purpose before the Do-while , for , IF , Else , While , and Switch Control constructs. for esample, the purpose of a for Loop Might Be to Examine All The Elements of An Array and The purpose of a Switch Might be determine The Effect of a Particular Character on The Column Number When Output. Control Construction WHich Result in Discontinuous Flow Control ( Break , Continue , and goto ), Except Break AT THE END OF A Switch Case Or Default, Should Be Commented with a Statement Of Explanation and Destination Action. for example: / * PARSE LINES OF INPUT INTO TOKENS Until End-of-file. * / While (exparse_line)! = EOF) { ... / * Do a quick comment check on the first token. * / IF (Expeek_Token () == Excomment) { / * * There is no need to parse this line further; * Resume Parsing at the next line. * / CONTINUE; } ... } / * End of per-line paarsing * / Falling through from one case to another in a Switch Statement Must Be Commented. In a long control construct, the closing brace '}' Must Be Commented to associate it with the opening statement. Since Window Sizes Vary, The Threshold for What CONSTITUTES A Long Construct Is About 20 To 30 Lines. Calls to Non-Returning Functions - Ons That Do Not Return Control to the calling function - Must Be Clearly Comment to State this faAct. 6.11 White Space (1100.1200.10.6) Opening Braces '{' and Closing Braces '}' Must Be Surrounded By White Space, Except That a closing brace may be immediatelyfactory Followed by A Semicolon ';'. All Commas, Semicolons, Question-Marks, And Colons Must Befollowed by White Space. No White Space SHOULD EXST BETWEEN THE NAMES OF FUNCTIONS OR Function-Like Macros and The Left Pouthesis, or Between Array Names and The Left Square Bracket Which Follows The Name. for example: Bad Coding Practice: Exmacro (ABC, DEF); EXFUNC (); Array [sub] = ABC; Good Coding Practice: Exmacro (ABC, DEF); EXFUNC (); Array [sub] = ABC; Space after opening parenthesees' ('or square brackets' " And Before Closing Parenthese '') 'or Square Brackets']' Is Optional. All C Keywords Must Be Surrounded by White Space, Except That SEMICOLONS IMMEDIATELY FOLLOW Keywords and Left Parentheses IMMEDIATELY FOLLOW ASM and Sizeof . Table 4. C Keywords ASM Double IF Static Auto Else int Struct Break Entry Long Switch Case ENUM Register Typedef charr Extern Return union Continue Float Short unsigned DEFAULT for Signed Void DO goto Sizeof While The (Primary) Operators '->' and '.' Must Not Be Surrounded By White Space. Unary Operators Must Not Have White Space BetWeen THEM AND THE OPERANDS Upon Which They Operate. Binary Operators (Arithmetic, RELATIONAL, Bitwise, Logical, and Assignment) Must Be Surrounded by White Space. One Exception Is Multiplicative Operators ('*', '/', and '%'), Whose Surrounding Spaces May Be Eliminated in ON Two Factors to Visually Emphasize Precene Over The Additive Operators (' ' and binary '-'). for example: Bad Coding Practice: A * B / C D / * SUGGESTS (A * (B / C)) D) * / A * B / C D / * Defeats Purpose of White Space * / x = A | B | C X_ptr = & y IF ((x_ptr -> el & exchangek)! = 0) QuestionAble Coding Practice: A B * C - X / Y Good Coding Practice: (a * b) / c D X = a | b | c X_ptr = & y IF ((x_ptr-> el & exchange! = 0) See section 100.10.6.4 for a list of operators, precedens and associativity. 6.12 Code Layout (1100.1200.10.6) LINES LONGER THAN 80 Columns Should Be Avoided to Increase Code Readability On Screens and Listings. LONGER LINES SHOULD BE BROKEN UP And the Continuation Portions Indented Further. Acceptable Breaking Points Are At Major Operators or Commas. For Example, Thase Statements IF ( { } EXFUNC (HUGE_ARG, GARGANTUAN_ARG, LARGE_ARG); May Be Written IF (( ( { } EXFUNC (HUGE_ARG, Gargantuan_Arg, Large_arg; Indentation of Continuation Lines by Small Amounts Distinguishes them From The Bodies of Control Structure. Indentation to Line Up Arguments OR Parts of expressions looks neat. The Bodies of IF , Else , for , While , Do-while , and Switch Constructs Must Be Compound STATEMENTS (ENCLOSED IN BRACES) AND IND A FULL (8 Character) Tab-stop. Enclosing All Bodies in Braces Prevents Problems with Later Core Changes and Non-Standard-Conforming Macros Which May Expand to Multiple Statements OR Contain ' Else -Sess IF S '. The Following Forms Are Permitted for IF and IF-Else Statements (a Simple IF Contains Only the IF Portion; generally, there may be Zero or more Else IF Portions and zero oss Else PORTIONS: IF ( } else if ( ELSE IF ( {} }
Else}
{
}
THE FIRST FORM IS preferred for the greatest ease in readability and
Matching Braces, and is the only form constent with the placement of there
Opening brace in function definitions. Opening and Closing Braces Are Always
Required Around The Body of Conditional Expressions, Even WHEN THE BODY IN
The Condition IS A Single Statement (AS in The Examples Above).
The Null Statement Forms of The Null Statement Forms of There
for
and
While
LOOPS Are Emphasized
By Placing The Comment on The Line Following The Left Curly Brace As Follows:
For (
/ * Null body loop / * / * null body loop * /
}
The General Forms of The
for
and
While
Loops Should Be Arranged in The
Same Way As A Simple
IF
.
THE
Do-while
Statement
May Have Either of these Forms:
Do DO {
{
} while (}
While (
Note That The Terminating Semicolon of The Terminating SEMICOLON OF
Do-while
Does Not Repesent a null statement and is there
On The Same Line as The Same
While
, in contrast to the null
Statement Form of thiswhile
Loop.
The Formats for
Switch
Statements Are:
Switch (
{CASE A:
Case A:
Case B:
Case B:
...
DEFAULT:
DEFAULT:
}
Where
Break;
,
CONTINUE;
,
Return;
,
Return
, / * Notreached * /, or a commented falp-through.
Case
and
DEFAULT
ActionS stay not be individually enclosed in Braces
Unless-Scope Variables.
When EXInship Code Does Not Conform To The Standards, New
Code Should Be Added Using The EXISTINCY WILL ENHANCE
Code readability.
6.13 File and Function Layout (1100.1200.10.6)
The General Layout of a Source File Should Look Like The Following.
#includedes / * Except in the modularity environment * /
File-global #defines / * usually in header files * /
File-Global Data Definitions / * One Per Line, Commented * /
.
.
.
The General Layout of a Function Should Be As Follows:
Function (arg_1, arg_2, ..., arg_n)
.
.
.
Definitions> } If the function is static (SHOULD NOT HAVE SCOPE BEYOND THIS FILE AND Those That IT #include s), the Line Becomes Static 6.14 Module Declaration File Layout (1100.1200.10.6) The Module Declaration File ContainS Administrative Information Which Defines the actions for the software generation systems (sgs) Tools for That Module. The name of the module declaration file consists of the name of the Module Followed by the suffix ".md". a description of each section of the .md file is as fiveows: 6.14.1 Identification Section (1100.1200.10.6) The name, subsystem and a brief description of the module area . 6.14.2 Module Initialization Section Section Section (1100.1200.10.6) THIS Section Specifies The Type of .md File Which IS Dependent on The Product Created. Source Level Module Declaration Files with TYPE = SGS_SRC "Define the attributes needed to compile and askESEMBLE Source Files to create low-level object files. High level module decaration Files with TYPE = SGS_OBJ "define the Attributes Needed to Link Low-Level Products to Create High Level Object Files. Sub-System Level Module Declaration Files with TYPE = Collection "define the attributes needed to ide Identify the PRODUCTS CREATED by The Subsystem and used to create the pag-level products. This Section Also Indicates Preprocessor Macro Definitions, Field Update TYPE AND SYMBOLS, AND IDENTIFIES The Selector (s) for the module. a Partiallist of Selector Attributes Are EES - The EXECUTION ENVIRONMENT PSM - Switch Module Pam - Administrative Module Ookp - Code Specific to the OKP Process 6.14.3 Product Declaration Section Section (1100.1200.10.6) THIS Section Lists The Products That Can Be Generated for this Module. 6.14.4 Product Definition Section (1100.1200.10.6) This section spells out the resources needed to generate the declared Products. for modules That Generate More Than Ooney Product The Attributes Associated With each product is doe by using the #ifprod Statements Followed by The Product Name. All Source and Headers Files Used For Specific Products Need to BE #if 'D for That Product. Processing Files Not Needed for the Product Results IN WASTING RESOURCES. This section is composed of: Package Identifier Which Associates a product with a specific loading. Component Identifier Lists All Modules That this Module Is Dependent Upon. Header Section Lists all The Local Header Files in The Module. Interface section Which Is The "Uses" Section Consisting of The Lists of Global and Local Interfaces That is receded to generate the product. Source File Section Which Contains the list of all source files in the module. FOLLOWING IS AN EXAMPLE OUTLINE for a Low-Level Module Declaration File: / * Module = RTXMFC * / ----------- | / * EXPORT MULTIFREQUENCY Compelle Signal * / | --- Identification --- / * Ss = RTA * / ___________ | section TYPE = SGS_SRC; ----------- | FU_TYPE = Nonkillable; | #IF (PAM) | procName = OKP; | #ENDIF | Module PrDefs = "-dflctoll" | --- inTIALIZATION --- ; / * End pre-processor list * / | section | SELECTOR = PAM | PSM | ; / * End selector list * / ----------- | Product = ----------- | RTAM_MFC / * MFC AM Product * / | Product RTSM_MFC / * MFC SM Product * / | --- Declaration ; / * End product list * / ----------- | Section #if (PAM) ----------- | Product #ifprod (RTAM_MFC) | --- Definition --- Package = lp_exp | section MFC_BASE | ; / * End package list * / | | Header = | --- Header RTammondata.h | section RTMONSTAT.H | / * Module Scope * / | TRTAM_MFC.H / * TEMPLATES for * / | / * Defined funcs * / | ; / * End header list * / | | Uses = | --- Uses --- / * Global and SS * / | Section RTA / TRTAM_MFC.H / * Scope Templates * / | TRTAM_MFC.H / * for defined * / | / * functions * / | | HM / THMLIB.C3O.H / * GLOBAL and SS * / | Si / TDDLIB.H / * Scope Templates * / | TRTX_TERM.H / * for Reference * / | / * functions * / | #ifpack (lp_exp) | DB / DMGPORT.H | DB / DMPORT_STATE.H | DB / RLPORTLA.H | #ENDIF | PAG / GLTPAMFC.H | RTA / RTMFCMONDS.H | RTA / RTPRIMTIVES.H | RTA / RTRETRNS.H | ; / * End buy list * / | | #ifpack (lp_exp) | --- Source --- Source = | section RTMFC_RSIG.C | RTMFC_SSIG.C | RTMFC_TSIG.C | RTMFC_VSIG.C | ; / * End source list for lp_exp * / | #ENDIF | | #ifpack (mfc_base) | Source = | RTMFC_OUT.C | RTMFC_REC.C | RTMFC_SEND.C | RTMFC_ERR.C | ; / * End source list for mfc_base * / | #ENDIF | #ENDIF | #ENDIF ---------- 7. Some Programming TIPS (1100.1200.10.7) BE CONSISTENT! For Example, IF you choose a style of indentation, And Establish Conventions for Using White Space and Naming Variables, Make Sure You Use the Same Style And conferenceions throughout your software. Write Clearly Don't Be Too Clever And Don't SacriFice Clarity for minor improvements in effect. Say What You Mean, Simply and Directly. Use library or standard functions where possible. Use Fundamental Control Construction Such Aswhile , Do-while , for and IF-Else And Avoid USING THE goto Statement. USE Switch When Feasible Instead of IF-else. Don't Comment or Work Around (Kludge) Bad CodeRewrite IT. Test Input for Validity and plausibility; Make Sure It Cannot Violate The Limits of Your Program. IF your program identifies Bad INPUT, Recover if Possible. Make Sure All Variables Are Initialized Before Use. Avoid Multiple Exits from loops. Make It Right and Clear Before You make it it. Also, Keep IT Right When You make it. Keep IT Simple to make it it. Let The Compiler Do The Simple Optimizations. Before "Tweaking" Code to make it faster, Try to find a better algorithm. Make Sure Comments and Code Agree. Format a program to help The Reader Understand IT. Comments shop not repeat what the code says; The Should Explain The Code. Don't over-comment. PARENTHESIZE TO AVOID OPERATOR-Precedence Ambiguity In Expressions Involving Mixed Operators, But do Not Overdo IT. Use symbolic constants instead of hard-code. (The Constants 0 and 1 May Appear as counter values.) Avoid Side Effects and Expressions in Which To ORDER OF Evaluation IS Undefined. Watch out for off-by-one errors, especially in Array Subscripts and loop indices. More about programing tips can be found in Reference [B], From Which Most of these WERE TAKEN. 8. References (1100.1200.10.8) 8.1 About The References (1100.1200.10.8) There Are Many References on Good Coding style, format and techniques. An Excellent Reference In this Area IS [B]. This Book Presents Examples of Both Good And Bad Programming Styles and Techniques And Explains Very Clearly What Makes Them So.Even though The Examples Are All in Fortran and PL / I, And some of the rules do not apply to c or 5ss Switch Developments, IT STILL PRESENTS Invaluable Ideas in Programming. The C Programming Language Book (Reference [A]) IS NOT a good reason for 5ss switch code. Many of the programming example in this guide Use Obscure Combinations of Language Features And is poorly formatted for clarity and readability. NeVERTheless, this book is an estortant source Of Information on C's Interpretation of Various Constructs and it points out some of the pitfalls. ANY C Programmer Would Greatle BENEFIT from READ GREATLY Reference [A] and reference [b]. 8.2 References (1100.1200.10.8) B. W. Kernighan and D. M. Ritchie, The C Programming Language , SECOND Edition, Prentice Hall, 1988 B. W. Kernighan and P. J. Plauger, The Elements of Programming Style , SECOND Edition, McGraw Hill, 1978 T. A. Burrows and D. D. Hill, C C codeing style for Conceptual Portability , 55641-810921.01TM, Case 40548-400 September 21, 1981. J. H. Miller, A proposed documentation naming scheme for no.5 Ess Software , 5326-780725.01MF, Case 40288-700, July 25, 1978. N. A. Martellotto, Department 5521 Routine Header Standards October 6, 1977. D. F. Christian, No. 5 Ess Coding Style , Programmer's Notes, July 26, 1982. C. G. denenberg, T. G. Peterson and T. L. Shockey, Programming Techniques Recommendations , Case 40125, February 19, 1976. C. M. Waters, Dynamic Data Design Guidelines , Case 40288-200, May 19, 1982. J. M. Milner, Impact of get use of asseore language programming by NO. 5 ESS , 5632-801216.01MF, Case 40288-700, December 16, 1980. P. W. Rung, Use of External and Static Variables for NO 5 Ess Im Software Developments , 5613-800625.01MF, CASE 49460-210, June 25, 1980. C. J. Hughes, Proposed Standards for Prorogues for NO. 5 Ess Software , 5613-800718.01MF, Case 49460-325, July 18, 1980. D. R. Kertz, No. 5 ESS - LINT LIBRARIES for Interface CHECKING , Case 40288-100, August 25, 1980. D. M. de Ruyck, "C" Language Unions Cause Machine Dependent Code , 55622-820503.01MF, Case 40288-700, May 3, 1982. J. R. Gibbons, No. 5 Ess Incremental Feature Addition (Feature Optioning) - System Level Requirements and Development Proposal , 55623-820412.01MF, CASE 40288-100, April 12, 1982. M. D. Bratcher, Coding Techniques, Style and Format , 55625.821108.02mF, November 8, 1982. R. A. Horzempa, CMS featuring support , 45182-811001.01MF, Case 40125. D. M. Ritchie, The C Programming Language - Reference Manual , (Section D.1.1 OF) Documents for UNIX ), Bell TELEPHONE Laboratories, Inc., 1981. Mary Pasternak, Efficient C C Coding Style for MC68 - ISSUE 2 , Work Project 1211-50-7062, Case 40297-2, March 21,1988. 9. Glossary (1100.1200.10.9) Assert Asserts Are A Mechanism Used by the 5ss® Switch Software To Identify Potential Problems and Report The TO Operating Personnel. Braces An Open Brace Looks Like `{', And A Close Brace Looks Like`}'. See Also Brackets. Brackets An Open Bracket Looks Like `[', And A Close Bracket Looks Like`]'. There Are Sometimes Referred To As Square Brackets to Differentiate THEM FROM Angle Brackets (An Open Angle Bracket Is The Less-Than Symbol `<', And a close Angle Bracket is the Greater-Than Symbol `> '). Category Code TWO-Letter Identifier Given To Cohesive Sections of 5ss Switch Code, Usually, But Not Limited to, Subsystems CMS Change Management System Dart Debug a Running Target. This is a Tool That Allows Software Running On The 3b20d to be debugged from a support processor. ECMS Extended Change Management System IMR Initial Modification Request ITS Interactive test system. This is a Tool buy to debug software running On The Processors in A Switch Other Than THE AM (3B20D). M4 Macro Processor NLINT Lint Is a Program To Check C C code for Bugs, Nonportable Constructions, And Waste. See the NLINT (1) Manual Page for more information. ODD Office Dependent Data Operator Associative Operator Associative Determines The Order in Which Adjacent Operators of Equal Precedence Are Evaluated. for Example, The Subtraction Operator HAS Left-to-Right Associative, SO `5 - 2 - 1 'Is Equivalent to` (5 - 2) - 1', For A Result of 2, NOT `5 - (2 - 1) ', Which Would Give A Result of 4. In Contrast, The Conditional Operator Has Right-To-Left Associative, SO `1? 1: 1? 2: 2 'Is Evaluated AS` 1? 1: (1? 2: 2)', Giving The Result 1, Rather Than `(1? 1: 1)? 2: 2 ', Which Gives The Result 2. Operator Precedence Operator precedence determines the Order in Which Expressions Involving DiffERENT OPERATORS Are Evaluated. Operators with Higher Precedence Are Evaluated Before Operators of Lower Precedence. for Example, THE Multiplication Operator `* 'Has Higher Precedency Than THE SUBTRACTION Operator `- ', so the expression` 7 - 3 * 2' is computed by first multiplying 3 by 2 and the subtracting the result from 7. RTR Real Time Reliable Sign Extension Sign Extension is a process for converting a small sign. The high-order bit of the smaller integer is replicated In The Additional Bits of The Larger Integer. White Space A Character Insert by Hitting Space Bar, Tab Character OR A Control Character. Zero-Padding In The Context of Integer Conversion, ZERO-PADDING Means That That High-Order Bits of An Integer Are Set To Zero When Converting from A Smalller Integer. 10. INDEX (1100.1200.10.10) #define ... 1200.10.4, 1-2; 1200.10.5, 6-9; 1200.10.6, 4, 6, 10-12, 14, 17-18 #ELIF ... 1200.10.6, 10 #ELSE ... 1200.10.5, 1,4; 1200.10.6, 8, 10-11, 13-14, 16 #ndfeature ... 1200.10.5, 9-11 #if ... 1200.10.3, 2; 1200.10.4, 1-5; 1200.10.5, 4, 9-10; 1200.10.6, 1-8, 10-11, 13-16, 18, 21; 1200.10.7, 1 #ifdef ... 1200.10.4, 5; 1200.10.6, 10-11 #ifndef ... 1200.10.6, 10 #undef ... 1200.10.4, 2 Dart ... 1200.10.9, 1 ITS ... 1200.10.9, 1 M4 ... 1200.10.4, 1-2; 1200.10.9, 1 RTR ... 1200.10.1, 1; 1200.10.2, 1; 1200.10.3, 1; 1200.10.4, 2; 1200.10.9, 1 Array IND ... 1200.10.7, 1 Array Names ... 1200.10.6, 6 ASM ... 1200.10.6, 14 AUTO ... 1200.10.6, 5, 14 Bit Field ... 1200.10.5, 7-9; 1200.10.6, 5 Block Comments ... 1200.10.6, 13 Braces ... 1200.10.6, 14, 16-17 1200.10.9, 1 Break ... 1200.10.4, 4; 1200.10.5, 3-4; 1200.10.6, 7-8, 14-15, 17 Category Code ... 1200.10.4, 1-3; 1200.10.9, 1 Commas ... 1200.10.6, 8, 15 Comment ... 1200.10.1, 1; 1200.10.5, 4; 1200.10.6, 1-2, 5, 12-14, 16-17; 1200.10.7, 1 Comment Styles ... 1200.10.6, 12 Compiler ... 1200.10.4,1; 1200.10.5, 2; 1200.10.6, 1-2, 5-7, 18 Compiler Dependent. ... 1200.10.5, 2; 1200.10.6, 5, 18 Constensency ... 1200.10.5, 9 CONSTANTS ... 1200.10.1, 1; 1200.10.4, 2; 1200.10.5, 8; 1200.10.6, 6, 11; 1200.10.7, 1 Continuation Lines ... 1200.10.5, 9; 1200.10.6, 15Continue ... 1200.10.5, 4; 1200.10.6, 4, 14, 17 CONTROL ... 1200.10.3, 2; 1200.10.5, 1, 4-5; 1200.10.6, 1, 12, 14; 1200.10.9, 2 Customers ... 1200.10.1, 1; 1200.10.2, 1 Data Declarations ... 1200.10.6, 3-4 Debugging ... 1200.10.4, 4-5; 1200.10.5, 1; 1200.10.6, 6; 1200.10.9, 1 DEFAULT ... 1200.10.4, 2; 1200.10.5, 4; 1200.10.6, 2, 8, 14, 17 Definitions ... 1200.10.2, 1; 1200.10.5, 9; 1200.10.6, 1, 4-6, 10-13, 16-18 Do-while ... 1200.10.5, 4; 1200.10.6, 11, 13, 16-17; 1200.10.7, 1 Efficiency ... 1200.10.6, 5 Else ... 1200.10.5, 1, 4; 1200.10.6, 8, 10-11, 13-14, 16 ELSE-IF ... 1200.10.5, 4 Embedded Assignment ... 1200.10.5, 1 ENUM ... 1200.10.4, 2-3; 1200.10.5, 6, 8-9; 1200.10.6, 14 ENUM Member ... 1200.10.4, 2-3 Falling through ... 1200.10.5, 4; 1200.10.6, 14 File ... 1200.10.3, 0-2; 1200.10.4, 0-2; 1200.10.5, 0, 9; 1200.10.6, 0-4, 10, 13-14, 17-20 File prologue ... 1200.10.2, 1; 1200.10.3, 1; 1200.10.6, 13, 17 Flexibility ... 1200.10.6, 1 Flow Control ... 1200.10.5, 4; 1200.10.6, 14 For ... 1200.10.1, 1; 1200.10.2, 1; 1200.10.3, 1-2; 1200.10.4, 1-5; 1200.10.5, 1, 3-5, 7-11; 1200.10.6, 1-7, 9-18, 20-21; 1200.10.7, 1; 1200.10.8, 1-2; 1200.10.9, 1-2 Function ... 1200.10.2,1; 1200.10.3,1-2; 1200.10.4, 1-5; 1200.10.5, 4-5; 1200.10.6, 1-7, 10, 13-14, 16-18, 21; 1200.10.7, 1 Function Call Parameters ... 1200.10.5, 5 Function names ... 1200.10.2, 1; 1200.10.3, 1-2; 1200.10.4, 1-2; 1200.10.6, 2 Function prologue ... 1200.10.2, 1; 1200.10.3, 1; 1200.10.6, 13, 17 Global Parameters ... 1200.10.4, 2; 1200.10.6, 7 Global Scope ... 1200.10.6, 3-4, 21 Global Variables ... 1200.10.4, 2 Goto ... 1200.10.4, 4-5; 1200.10.5, 3-4; 1200.10.6, 14; 1200.10.7, 1 Header File ... 1200.30.3, 1-2; 1200.10.4, 2; 1200.10.6, 1-4, 10, 17, 19 Identifier ... 1200.10.4,1-2; 1200.10.6,19; 1200.10.9, 1iF ... 1200.10.3, 2; 1200.10.4, 1-5; 1200.10.5, 4, 9-10; 1200.10.6, 1-8, 10-11, 13-16, 18, 21; 1200.10.7, 1 IF-Else ... 1200.10.6, 11, 16; 1200.10.7, 1 Indentation ... 1200.10.6, 16 Initialization ... 1200.10.6, 18 INT ... 1200.10.6, 2, 5-6, 13-14 Keywords ... 1200.10.4, 1; 1200.10.6, 14 Language ... 1200.10.1, 1; 1200.10.2, 1; 1200.10.4, 1; 1200.10.8, 1-2 LINT ... 1200.10.6, 11; 1200.10.8, 1; 1200.10.9, 1 Local Constants ... 1200.10.6, 6 Local Variables ... 1200.10.6, 6-7, 17 Logic ... 1200.10.5, 1 Logic control. ... 1200.10.5, 1 LOOP ... 1200.10.4, 2, 4; 1200.10.5, 3-5, 7; 1200.10.6, 11, 14, 16-17; 1200.10.7, 1 LOOP Variable ... 1200.10.4, 2; 1200.10.5, 3-4 Macro Definition ... 1200.10.6, 4, 11-12, 18 Macros ... 1200.10.4, 1-2; 1200.10.5, 5; 1200.10.6, 4, 11-12, 14, 16, 18; 1200.10.9, 1 Maintainability ... 1200.10.5, 0-1 Maintenance ... 1200.10.1, 1; 1200.10.2, 1; 1200.10.5, 9; 1200.10.6, 3 Module Declaration File. ... 1200.10.6, 1, 3-4, 10, 18, 20 Module Name ... 1200.10.4, 1; 1200.10.6, 2, 18 NLINT ... 1200.10.4, 5; 1200.10.6, 13; 1200.10.9, 1 Non-Returning functions ... 1200.10.5, 4 NULL ... 1200.10.5, 1-2; 1200.10.6, 5, 13, 16-17 Operator precedence ... 1200.10.6, 9; 1200.10.9, 1 Operators ... 1200.10.5, 7; 1200.10.6, 8-9, 11, 15; 1200.10.7, 1; 1200.10.9, 1 ParentheSes ... 1200.10.6, 9, 14 Pointer ... 1200.10.5, 6 Precedence ... 1200.10.3, 1; 1200.10.6, 1, 4, 8-10, 12-13; 1200.10.9, 1 Range ... 1200.10.5, 4 Readability ... 1200.10.5, 4; 1200.10.6, 9, 16; 1200.10.8, 1 References ... 1200.10.4, 4-5; 1200.10.5, 3, 9, 11; 1200.10.6, 1, 3-7, 10, 21; 1200.10.7, 1; 1200.10.8, 0-2 Register variables ... 1200.10.6, 6 Return ... 1200.10.3, 1-2; 1200.10.5, 4-5; 1200.10.6, 1-2, 7, 14, 17-18 Return Type ... 1200.10.6, 1-2, 18 Return Values ... 1200.10.3, 1-2; 1200.10.6, 1-2scope ... 1200.10.6, 1-4, 18, 21 SEMICOLONS ... 1200.10.6, 11, 14, 17 Short ... 1200.10.4, 1; 1200.10.6, 5-6, 13-14 Side Effects ... 1200.10.3, 2 SIGN EXTENSION ... 1200.10.6, 5-6; 1200.10.9, 2 SINGLE-LINE Comments ... 1200.10.6, 13 SizeOf ... 1200.10.6, 8, 11, 14 Source File ... 1200.10.3, 1; 1200.10.4, 1; 1200.10.5, 9; 1200.10.6, 3-4, 10, 18-19 Static ... 1200.10.6, 1,14; 1200.10.8, 1 Struct ... 1200.10.4, 4; 1200.10.5, 6, 8; 1200.10.6, 4, 7-8, 14 Struct / Union Member ... 1200.10.4, 2 Struct / Union / Enum Tag ... 1200.10.4, 2 Structure ... 1200.10.4, 2-3; 1200.10.5, 6; 1200.10.6, 6-7, 12, 16 Subsystem ... 1200.10.3, 1; 1200.10.4, 1; 1200.10.6, 1-4, 18; 1200.10.9, 1 Suffix. ... 1200.10.4, 1; 1200.10.6, 18 Switch ... 1200.10.1, 1; 1200.10.2, 1; 1200.10.3, 1; 1200.10.4, 1-4; 1200.10.5, 3-4; 1200.10.6, 8, 13-14, 16-18; 1200.10.7, 1; 1200.10.8, 1; 1200.10.9, 1 TAG ... 1200.10.4, 2-4; 1200.10.5, 6 Trailing Comments ... 1200.10.6, 13, 17 TYPE CASTS ... 1200.10.6, 5 TYPEDEF ... 1200.10.4, 2-4; 1200.10.5, 9; 1200.10.6, 14 Union ... 1200.10.4, 3; 1200.10.5, 6; 1200.10.6, 4, 7, 14; 1200.10.8, 1 Unsigned ... 1200.10.5, 8; 1200.10.6, 5-6, 14 Unsigned char ... 1200.10.6, 5,14 Unsigned int ... 1200.10.6, 5-6, 14 Unsigned long ... 1200.10.5, 8; 1200.10.6, 6, 14 Unsigned short ... 1200.10.6, 5,14 Variable ... 1200.10.4, 2; 1200.10.5, 3-4, 6; 1200.10.6, 4-7, 12, 17; 1200.10.7, 1; 1200.10.8, 1 Void ... 1200.10.6, 2,14 While ... 1200.10.5, 3-4; 1200.10.6, 11, 13-14, 16-17; 1200.10.7, 1 White Space ... 1200.10.6, 9, 13-15; 1200.10.9, 2 ZERO-PADDING ... 1200.10.6, 6; 1200.10.9, 2 11. Attachment - 5ss Category Codes (1100.1200.10.100) All Category Codes Should Consist of Two Letters (Some Exceptions May EXIST for Historical Reasons. The Letters Will Appear As Upper Case or Lower Case, Depending Onwhere They Are Being Used (See Table 1 in Section 100.10.4). IF you add a new category code, you must imr this document and have Itadded to the list. Table 5. 5. 5ss Category Code Definitions 5ss Category Codes Category Code Category Code Definition Subsystem (s) AC Automatic Call Distributor RTA AM Automatic Message Accounting AMA Ar Assert Range (all) AS Administrative Services AS Au Application Audits Au BC Book Call Kernel Process OA CC Common channel signaling CCS CD Control Distribution Unit SM SMMS CH Core Hardware SM CI Call Intercept AS CRA OP CI Control Interface Hardware Drivers PC SM Cm Interprocessor Communication System Cm CN Common Network Interface CNI CO Cutover RTA Cot Customer Originated Trace AS CR Call Record Assembler Cra CT Circuit DN CT Central Trunk Test Unit TM CT CCS Transport CCS DA Dynamic Access DA DB Data Base DA DATA DB DC Digital Cellular Switch (D-AMPS DCS) FC DC Directly Connected Test Unit TM DD Data Delivery Si DF Code on DFI's HW DG Diagnostics Supervisor DG DL Code on IDCU DLP HW DN Diagnostics DN DNC Diagnostics DNCP DS Code on DSU HW DT Data Transport Si DT ECD / SG Databases and Related Tools ECDSG DTL Data Transfer Link AS DTP Data Transfer Process AS EC External Data Link Communication Package AS EE Execution Environment Support Code (EES LOADS ONLY) FC Feature Control FC FP Fi Feature Control for Isdn Fita FP Feature Pots FP FW FIRMWARE SMFW GB Generic Backup Si GD Global Data Gdata GF General File Server AS GR Generic Retrofit GR HM Human Machine Interface HM TYMSG HW [Code on Peripheral] Hardware (islu) HW IB ISDN Bellcore Services Fita Id Code on idcu HW IM Integrity Monitor Si In Initialization Si IP Code on idcu and islu2 rtx HW IS ISDN Feature Control FC Fita IS Code on islu2 HW B PC Foreground Jobs PC Ka Keep Alive Au Lg Logging DB Li Link Interface PC LP Logical Port PC LS Code on IDCU LSI HW LT Load Origination Test System Lots MC Feature Control FC Ml MLT - 2 (Mechanized Loop Testing) Support TM Mn Monitoring OA Mm MultiMetering AS MS Measurements AS Nm NetWork Management Nm NP NetWork Protocol OP OA OSPS Operator Action OA OC Overload Control Si OD Online Data Integrity (ODIN) OD OP OSPS OP OP Abstract Device Operation PCTM Oral Generated Optimized Read Functions DB Oral Office Records RC OS Operating system OS PC Peripheral Control PC Pg PRL generated code DB RC PH PC Network Control (Paths) PC Pi Packet interface SMIM PL Code on IDCU PLS HW PL Population Rule Language DB RC PP Switch maintenance for ph or Pi SMIM PR Packet routing PR PS Packet Services PS QC Generated Virtual Relation Query Code Functions DB QGP QLPS Gateway Processor SMIM RC Recent change OD RC Rcm Recent Change Module RC RE Remote Electronic Storage Device RC Ri Request isdn [Transport and Access] Rita RT Routing and Terminal Allocation RTA SB System backup Si SE Service evAluation AS SO Service Observation AS Si System integrity Si SL Subscriber Line and Instrument Measurement Circuit Pack SLIM2 SM Switch maintenance SM SMIM SP TSI Signal Processor Hardware Drivers PC SS Service Switching Point CCS ST Software Test System STS TL Tools TL TM Terminal Maintenance TM TP Transport Protocol OP TP Transaction Population (Rule Language) RC TS Time Slot Interchanger Hardware Drivers PC Ty [Teletype] INPUT and OUTPUT MESSAGES TYMSG UA Unix availability UA UP Program Update UP UT Utilities UT VFSM Virtual Finite State Machine Glib WE [Western Electric] TEST & CUTOVER UTILITIES WE A Few Category Codes Have Special, Restricted Uses. The Following Table. Table 6. Special Or Restricted Category Codes Category Code Description Al, Al Used Only in tags and typedefs for alternate structures for Relations; Defined Only In UHDR / DB / RL * .G Files AV, AV Used Only in tags and typedefs for alternate structures for Recent Change Views; Defined Only In RC / HDR / RV * .L Files BF Used Only In #defined name for size of bit fields; defined Only in Files That Define a Typedef Type That May NEED TO Be buy as a bitfield in Some Structure DM, DM Used Only in Tags and TypedEfs and in Tags and TypedEfs and in Tags and Typed Define these Types; Defined Only in UHDR / DB / DM * .G GL, GL Used Only in Global Parameters, And In #defined Symbols and Enum MEMBERS in Global Headers for Data, DB, GData, PAG, And RDL MG, MG Used Only In Tags for Message Structure, Message ID #defined Symbols, and in the MDL File Names That Define these Types; Defined Only in UHDR / SS / MG * .G AND SS / HDR / MG * .L Files, And in UHDR / PAG / GLMSGIDS.G. RL, RL Used Only in Tags for Relation Structure, RELATION ID #defined Symbols, and in the rdl file Names That Define these Types and their corresponding prl files (RDL / POPRULES / RL * .P); Defined Only In UHDR / DB / RL * .G, And UHDR / DB / DBRELIDS.G. RV, RV Used Only in tags for view structures, view id #defined Symbols, and in the VDL File names; defined Only In RC / HDR / RV * .L Files, And UHDR / RC / RCViewIDS.G. SZ Used Only in #defined Names for Size of Arrays (Number of Elements); Defined Only In Files That Define a typedef type That May Need To Be Used as an Array 12. Attachment 200 - File Suffixes (1100.1200.10.200) The Following Table Lists the Most Commonly Used File Suffixes. Some Subsystems May Define Additional Suffixes. The "Project" Column Idicates the Source of the Suffix. Table 7. File Suffixes PROJECT SUFFIX SUFFIX DESCRIPTION 5ers RTR AFMT Acknowledge format File Format file x b Specification file x c C Language Source File x x C C Language Source File Which Needs M4 Macro Preprocessing x x di Generated Diagnostics Data File x Di Diagnostics Input Data file x fly Generated Diagnostics Data File x Fly Diagnostics Input Data file x FMT Input Message Format File x G Unprocessed Global Header File (Must Be in UHDR / SS) x hide Module Local Header File x hide Header File (Local and Global) x Hide Header File (Local and Global) x in Input File for Makefile x ITY, ITY File Defining Input Message x l Lex Source File x x LH Module Local Header File for SDL x L Unprocessed Subsystem Local Header File (Must Be in SS / HDR) x MD Module Descriptor File (The Name Before The Period Match The Name of the module it is in x Ofmt Output Message Format File x OTY, OTY File Defining Output Message x p, p PRL4.0 Source File (Must Be Under Rdl / Poprules) x r PRL5.0 Source File (Must Be Under Rdl / Poprules) x s askEMBLY LANGUAGE FILE x x SD SDL Source File x SP Module Interface Description File x S Assembly Language Source File Which Needs M4 Macro PreProcessingX v Delta Files Created by The Vcompress / VDELTA UNIX Process x V EVL Files Used by the Brev Process for the EVL CODE x y Yacc Source File x x Converted by SGML2HTML 1.5 on Thursday, May 16, 2002 5:40 AM