C
Language
Doc No: DGL 01
Approved by
Issuing Authority
HEAD,
Quality Assurance Department
C-DAC (T)
Vellayambalam, Thiruvananthapuram
Copyright
No part of this document
may be reproduced in any form
without the prior permission in writing
of issuing authority
AMENDMENT HISTORY
1. Issue History
Issue
No
Effective
From
08-Dec2011
Total
Doc.
Pages
Change Report
Number / Date
NA
10
--
Date: 24-11-2011
Effective
From
Revised/ Page
Total
Brief Description of change
Added Rev.
Doc.
(If change is major, give document change report number/date only)
Page No No.
Pages
Approved by
(Signature)
Doc. Name :
Table of Contents
Sl. No
Page
No
2
CONTENTS
1.
Scope
2.
2
Notations Used
3.
2
File and Folder Structure
4.
2
Program File Names
5.
3
Program File Header
6.
4
#define Statements
7.
4
Variables
8.
5
Structures
9.
6
Function Declaration
10.
7
Function Header
11.
7
Loops
12.
8
Branches
13.
9
Assignment Statements
14.
10
Comment Statements
15.
10
Coding Guidelines
Doc Name:
Page No: 1
1. SCOPE
This document deals with the Coding Standards to be followed while writing the C code for
various software processes being developed in connection with the Compact TETRA Base
station project. However, it is not mandatory to use this standard, but if not used, the developer
should follow the QA Procedure for this purpose.
2. NOTATIONS USED
UPPER CASE :
lower case:
Title Case:
<space>:
UPPERCASE
lowercase
TitleCase
The space character
Each implementation file shall have its corresponding header file wherever required
Each software module shall have a root folder named after that module
All project related files and other common/shared files shall come under the root folder
All implementation files shall come under a single folder named Source
All header files shall come under a single folder named Header
If any custom made library files are used, those library files shall come under a single
folder named Library
Doc Name:
Page No: 2
FilePurpose:
ext:
Example:
5. PROGRAM HEADER
Each header/implementation file shall start with a header in the following format.
/*######################################################################
#
#
File Name:
#
########################################################################
#
# Project Name
:
#
# Project Code
:
#
# Created
:
#
# Purpose
:
#
# Description
:
#
# Author(s)
:
#
# Version No
:
#
# Revisions
:
#
# Remarks
:
#
# Copyright
######################################################################*/
Project Name:
Project code:
Created:
Purpose:
Description:
Author(s):
Version No:
Revisions:
Remarks:
Doc Name:
Page No: 3
Copyright statement
Copyright:
Note:
#define LABEL
Example:
#define MAX_BUFFER_SIZE
500
7. VARIABLES
All variable names shall start with VariableScope followed by VariableDatatype and
VariablePurpose each of which separated by underscore (_).
Syntax:
VariableScopeVariableDatatype_VariablePurpose
VariableScope:
VariableDatatype:
VariablePurpose:
Example:
luint16_ReceiveInterruptCount
gpuint16_ReceiveData
Doc Name:
Page No: 4
Exceptions:
Loop variables, Structure field variables etc.
8. STRUCTURES
All structures shall be type defined using the typedef statement. All structure declarations
shall follow the following format.
Syntax:
Declaration:
typedef struct STRUCT_STRUCTURE_NAME
{
Datatype Datatype_FieldName1;
Datatype Datatype_FieldName2;
..
..
..
} StructureName;
STRUCT_STRUCTURE_NAME:
Datatype_FieldName:
StructureName:
Instantiation:
StructureName VariableScopeStructureName_StructureVariablePurpose;
VariableScope:
StructureName:
Doc Name:
Page No: 5
StructureVariablePurpose:
Example:
Declaration:
typedef struct STRUCT_DATE
{
uchar uchar_Day;
uchar uchar_Month;
uint16 uint16_Year;
}Date;
Instantiation:
Date gDate_RegistrationDate:
variable.
9. FUNCTION DECLARATION
All Function names shall start with FunctionReturnDatatype,
FunctionPurpose each of which separated by underscore (_).
followed
by
Syntax:
FunctionReturnDatatype FunctionReturnDatatype_FunctionPurpose
FunctionReturnDatatype:
FunctionPurpose:
Example:
uint16 uint16_SendMessage (IPAddress lIPAddress_Destination, char
*lpchar_Buffer, int16 lint16_BufferSize)
{
statement1;
statement2;
}
Doc Name:
Page No: 6
Note:
All abbreviations that are used in File name, Variable name or Function name shall be
in UPPER CASE.
10. FUNCTION HEADER
Each function shall have a header in the following format. The header shall just precede the
function definition.
/*###################################################################
#
#
Function Name:
#
#####################################################################
#
# Arguments
:
#
# Description
:
#
# Return Type :
#
# Remarks
:
#
###################################################################*/
Arguments:
Description:
Return Type:
Remarks:
11.
LOOPS
All loops shall have the following format.
Syntax:
for<space>(start;<space>condition;<space>increment)
{
statement(s);
}
while<space>(condition)
{
statement(s); }
Doc Name:
Page No: 7
Example:
for (i=1; i<10; i++)
{
statement1;
statement2;
}
while (i<10)
{
statement1;
statement2;
}
12. BRANCHES
All branching statements shall have the following format.
Syntax:
if<space>(condition1)
{
statement(s);
}
else if<space>(condition1<space>&&<space>condition2)
{
statement(s);
}
else
{
statement(s);
}
switch<space>(variable)
{
case value1:
statement(s);
case value2:
statement(s); }
Example:
Doc Name:
Page No: 8
if (i>10)
{
statement1;
statement2;
}
else if (i>10 && i<15)
{
statement3;
statement4;
}
else
{
statement5;
}
switch (i)
{
case HIGH:
statement1;
break;
case LOW:
statement2;
break;
}
13. ASSIGNMENT STATEMENTS
All assignments shall be of the following format;
Syntax:
VariableName<space>=<space>value;
Example:
guint16_ReceiveInterruptCount = 0;
Doc Name:
Page No: 9
Syntax:
or
Example:
/* Sending the message */
//Sending the message
or
Doc Name:
Page No: 10