Anda di halaman 1dari 7

SW – C Coding Standard SV I IS

P730006L56 SW Process

1
Maturity DO/signature Check/signature(s) Release/signature
Released Process Owner Process Executive

Arno Semmelroth
SV I IS RD SW
Date: 14-Mar-05
e-Sign ListID: 28392
Transmittal, reproduction, dissemination and/or editing of this document as well as utilization of its contents and communication there of to others without express authorization are prohibited.

Process Manager

CJ.Bonetto Frans Bosch Bernd Ruthemeyer


SV I IS RD PTQ SV I IS RD PTQ SV I IS O PMC
Date: 10-Mar-05 Date: 10-Mar-05 Date: 23-Mar-05
e-Sign ListID: 28392 e-Sign ListID: 28392 e-Sign ListID: 28392
2

Title: SW – C Coding Standard


3
Purpose:
Offenders will be held liable for payment of damages. All rights created by patent grant or registration of a utility model or design patent are reserved.

This document defines C Coding Standard for the development of SW embedded in Automotive
Entertainment Systems and delivered to the customer.
4
Scope (validity area & date, replaced documents):
This Standard is valid for all C code, whether or not produced by subcontractors or development
partners under contract of Siemens VDO. Nevertheless they are not covering all aspects of necessary
or good coding. They need local and/or project specific supplements. These rules add to existing ones
and take precedence in case of differences or contradictions.
5

6 Table of contents
7 1 Process ................................................................................................................................................... 2
8 1.1 Introduction ......................................................................................................................................... 2
9 1.2 C Coding Guidelines ........................................................................................................................... 2
10 2 Metrics ..................................................................................................................................................... 4
11 3 Further explanations .............................................................................................................................. 4
12 3.1.1 International Character Sets ............................................................................................................ 4
13 3.1.2 POSIX .............................................................................................................................................. 4
14 3.1.3 Microprocessor interfaces ................................................................................................................ 4
15 4 Terminology, Definitions and Abbreviations ...................................................................................... 5
16 5 Related documents ................................................................................................................................ 5
17 5.1 Related upstream documents ............................................................................................................. 5
18 5.2 Further related documents .................................................................................................................. 5
19 5.3 Source of figures at this procedure ..................................................................................................... 5
20 6 Teams ...................................................................................................................................................... 6
21 6.1 Procedure Definition Team ................................................................................................................. 6
22 6.2 Review Team ...................................................................................................................................... 6
23 6.3 CCB Team .......................................................................................................................................... 6
24 6.4 Distribution List.................................................................................................................................... 7
25 6.5 History of Changes.............................................................................................................................. 7
26
27

28

Copyright © by Siemens AG 2004 For internal use only


All rights reserved 1/7 Printout from G+O portal
SW – C Coding Standard SV I IS

P730006L56 SW Process

1 1 Process
2 SV I IS SW Coding Rules & language independent Code Metrics are described in [U-1]. C Specific
3 Coding Guidelines are described here.

4 1.1 Introduction
Transmittal, reproduction, dissemination and/or editing of this document as well as utilization of its contents and communication there of to others without express authorization are prohibited.

5 MISRA has defined "Guidelines for the use of the C language in vehicle based software". HIS has
6 defined a subset of these coding guidelines. This subset can be seen as industry standard for C coding
7 guidelines in automotive industry. For more information see [R-1]
8
9 The following subset of MISRA Coding Guidelines for C is the SV I IS standard for C Coding Guidelines.

10 1.2 C Coding Guidelines


Offenders will be held liable for payment of damages. All rights created by patent grant or registration of a utility model or design patent are reserved.

11 Both "shall" and "should" describe mandatory requirements.


12 The rule numbers refer to the MISRA standard's rule numbering.
13
Mandatory Subset of MISRA Coding Guidelines as defined by HIS
Rule # Description
5 Only those escape sequences that are defined in the ISO C standard shall be used
7 Trigraphs shall not be used
9 Comments shall not be nested
13 The basic type of char, int, short, long, float or double should not be used, but specific-length
should be typedef'd for the specific compiler, and these type names used in the code.
14 The type char shall always be declared as unsigned char or signed char
16 The underlying bit representation of floating-point numbers shall not be used in any way by
the programmer
17 Typedef names shall not be reused.
19 Octal constants (other than zero) shall not be used.
21 Identifiers in an inner scope shall not use the same name as an identifier in the outer scope
and therefore hide that identifier.
22 Declaration of objects should be at function scope unless a wider scope is necessary.
23 All declarations at file scope should be static where possible.
25 An identifier with external linkage shall have exactly one external definition.
26 If objects or functions are declared more than once they shall have compatible declarations.
27 External objects should not be declared in more than one file.
29 The use of a tag shall agree with its declaration.
30 All automatic variables shall be assigned a value before being used.
31 Braces shall be used to indicate and match the structure in non-zero initializations of arrays
and structures.
32 In an enumerator list, the "=" construct shall not be used to explicitly initialize members other
than the first, unless all items are explicitly initialized.
33 The right hand operator of a logical && or || operator shall not contain side effects.
34 The operands of a logical && or || shall be primary expressions.
35 Assignment operators shall not be used in expressions which return Boolean values.
37 Bitwise operations shall not be performed on signed integer types.

Copyright © by Siemens AG 2004 For internal use only


All rights reserved 2/7 Printout from G+O portal
SW – C Coding Standard SV I IS

P730006L56 SW Process

38 The right-hand operator of a shift operator shall lie between zero and one less than the width
in bits of the left-hand operator (inclusive).
39 The unary minus operator shall not be applied to an unsigned expression.
40 The sizeof-operator should not be used on expressions that contain side effects.
43 Implicit conversions which may result in a loss of information shall not be used.
45 Type casting from any type to and from pointers shall not be used.
Transmittal, reproduction, dissemination and/or editing of this document as well as utilization of its contents and communication there of to others without express authorization are prohibited.

46 The value of an expression shall be the same under any order of evaluation the standard
permits.
48 Mixed precision arithmetic should use explicit casting to generate the desired result.
50 Floating point variables shall not be tested for explicit equality and inequality.
52 There shall be no unreachable code.
56 The goto statement shall not be used.
59 The statement forming the body of an if, else if, else, while, do… while or for statement shall
always be enclosed in braces.
Offenders will be held liable for payment of damages. All rights created by patent grant or registration of a utility model or design patent are reserved.

61 Every non-empty clause in a switch-statement shall be terminated with a break-statement.


62 All switch-statements should contain a final default-clause.
64 Every switch-statement shall have at least one case.
65 Floating point variables shall not be used as loop counters.
68 Functions shall always be declared on file scope.
69 Functions with variable number of arguments shall not be used.
70 Functions shall not call themselves, either directly or indirectly.
71 Functions shall always have prototype declarations and the prototype shall be visible at both
the function definition and call.
75 Every function shall have an explicit return type.
76 Functions with no parameters shall be declared with parameter type void.
78 The number of parameters passed to a function shall match the function prototype.
81 Const qualification should be used on function parameters which are passed by reference,
where it is intended that the function will not modify that parameter.
83 For functions with a non-void return type
i) there shall be one return statement for every exit branch (including the end of program)
ii) each return shall have an expression
iii) the return expression shall match the declared return type.
85 Functions called with no parameters should have empty parenthesis.
87 #include-statements in a file shall only be preceded by other preprocessor directives or by
comments.
88 Non-standard characters shall not occur in header file names in #include-directives.
89 The #include-directives shall be followed either by a <filename> or by a "filename"
sequence.
91 Macros shall not be #define'd and #undef'd within a block.
94 A function-like macro shall not be "called" without all of its arguments.
95 Arguments to a function-like macro shall not contain tokens that look like preprocessor-
directives.
96 In the definition of a function macro, the whole definition and each instance of a parameter
shall be enclosed in brackets.
98 There shall be at most one definition of the #- and ##-preprocessor operators in a single
macro definition.
99 All uses of the #pragma-directive shall be documented and explained.
100 The "defined" preprocessor-operators shall only be used in one of the two standard forms.

Copyright © by Siemens AG 2004 For internal use only


All rights reserved 3/7 Printout from G+O portal
SW – C Coding Standard SV I IS

P730006L56 SW Process

102 No more than 2 levels of pointer indirection should be used.


103 Relational operators shall not be applied to pointer types except where both operands are of
the same type and point to the same array, structure or union.
106 The address of an object with automatic storage shall not be assigned to an object which
may persist after the object has ceased to exist.
108 In the specification of a structure or union-type, all members of the structure or union shall
be fully specified.
Transmittal, reproduction, dissemination and/or editing of this document as well as utilization of its contents and communication there of to others without express authorization are prohibited.

109 Overlapping variable storage shall not be used.


112 Bit fields of type signed int shall be at least 2 bits long.
114 Reserved words or standard library function names shall not be redefined or undefined.
115 Standard library function names shall not be reused.
118 Dynamic heap memory allocation shall not be used.
119 The error indicator errno shall not be used.
120 The macro offsetof in library <stddef.h> shall not be used.
Offenders will be held liable for payment of damages. All rights created by patent grant or registration of a utility model or design patent are reserved.

122 The setjmp macro and the longjmp function shall not be used.
123 The signal handling facilities of <signal.h> shall not be used.
124 The input/output library <stdio.h> shall not be used in production code.
125 The library function atof, atoi and toll from library <stdlib.h> shall not be used.
126 The library function abort, exit, getenv and system from library <stdlib.h> shall not be used.
127 The time handling functions from library <time.h> shall not be used.
1

2 2 Metrics
3 Use metrics as defined in the document [R-2].

4 3 Further explanations
5 According to VW, every single violation of a rule has to be documented. The following exceptions apply
6 for SV I IS Code:

7 3.1.1 International Character Sets


8 For international (e.g. far-east) versions it may be necessary to deal with Unicode character sets.

9 3.1.2 POSIX
10 Third-party defined operating system interfaces and relating standards (e.g. POSIX) may violate several
11 rules. They may also lead to necessary violations within newly created source code e.g. necessary casts
12 between types declared in the software and types used in the interface.

13 3.1.3 Microprocessor interfaces


14 (From the MISRA Rules) Source code written to interface with the microprocessor hardware will
15 inevitably require the use of proprietary extensions to the language.

16

Copyright © by Siemens AG 2004 For internal use only


All rights reserved 4/7 Printout from G+O portal
SW – C Coding Standard SV I IS

P730006L56 SW Process

1 4 Terminology, Definitions and Abbreviations


2 Use SV I IS common Glossary of Abbreviations, Terms & Definitions – P300002L02.
3 For additional definitions or abbreviations use CR for Glossary - P300002F02.
4
Transmittal, reproduction, dissemination and/or editing of this document as well as utilization of its contents and communication there of to others without express authorization are prohibited.

5 Acronyms and Abbreviations


6 Specific acronyms / abbreviations, used only in this document:
7 HIS Herstellerinitiative Software (Manufacturer Initiative Software) http://www.automotive-
8 his.de/
9 MISRA Motor Industry Software Reliability Association
10
11 Definitions
12 Specific Definitions, used only in this document:
13 Trigraph (from C language) – any combination of two question marks with another character,
Offenders will be held liable for payment of damages. All rights created by patent grant or registration of a utility model or design patent are reserved.

14 such as??! Which is interpreted as a single | (bitwise or)

15 5 Related documents
16 5.1 Related upstream documents
17 [U-1] F730006LAF SW Coding Procedure, SV I IS
18
19 5.2 Further related documents
20 [R-1] MISRA C Guideline, can be found on Intranet G+O portal
21 [R-2] P730006LAY Measurement Procedure, SV I IS
22
23 5.3 Source of figures at this procedure
24 [F-1] …

25

Copyright © by Siemens AG 2004 For internal use only


All rights reserved 5/7 Printout from G+O portal
SW – C Coding Standard SV I IS

P730006L56 SW Process

1 6 Teams
2 6.1 Procedure Definition Team
Name Department Location
Transmittal, reproduction, dissemination and/or editing of this document as well as utilization of its contents and communication there of to others without express authorization are prohibited.

Christian-Jacques Bonetto SV I IS RD PTQ SAP


3
4 6.2 Review Team
Name Department Location
Arno Semmelroth SV I IS RD SW WET
Daniel Crane SV I IS RD SW HSV HSV
Norbert Burghardt SV I IS RD SW WET WET
Gerhard Gries SV I IS RD SW MCH MCH
Offenders will be held liable for payment of damages. All rights created by patent grant or registration of a utility model or design patent are reserved.

King Young Lee SV I IS RD SW SGP SGP


Luc Mordacq SV I IS RD SW RBT RBT
Reiner Seitz SV I IS RD SW TSR TSR
Jean-Marc Soyez SV I IS RD SW SAP SAP
Jean-Pierre Arragon SV I IS TLA RBT
Wolfgang Bauer SV I IS TLA MCH
Bernhard Klein SV I IS TLA RBG
Philippe Besson SV I IS Radio RBT
Steffen Zehner SV I IS CO ARN RBG
Michael Fischer SV I IS CO CMM WET
Evelyne Demarchez SV I IS CO FRW SAP
Hans Hermans SV I IS CO RRN EHV
Ralf Löffert SV I IS CO SSW WET
Uwe Schilling SV I IS CP WET
Peter Schless SV I IS RD PTQ MCH
Alwin Raaf SV I IS O PMC WET
Bernd Ruthemeyer SV I IS O PMC RBG
5
6 6.3 CCB Team
Name Department Location
Arno Semmelroth SV I IS RD SW WET
Peter Schless SV I IS RD PTQ MCH
Frans Bosch SV I IS RD PTQ EHV EHV
7
8

Copyright © by Siemens AG 2004 For internal use only


All rights reserved 6/7 Printout from G+O portal
SW – C Coding Standard SV I IS

P730006L56 SW Process

1 6.4 Distribution List


Intranet SV I IS G+O portal
2
3 6.5 History of Changes
Transmittal, reproduction, dissemination and/or editing of this document as well as utilization of its contents and communication there of to others without express authorization are prohibited.

At project start the latest version of this document has to be used. The latest version is available on
Intranet.
Version Status Date Name, Department Changes
<dd-Mmm-YY> (e.g. CR-number)
a01 Draft 27-Jul-04 Rikowski, SV I IS RD SW Adapted VW Coding Guidelines to
become general guidelines, adapted to
ISQP Template, added scope chapter
a02 Draft 29-July-04 Rikowski, SV I IS RD SW Updates after first review of some
specialists.
a03 Reviewed 19-Aug-04 Rikowski, SV I IS RD SW Update after general review.
Offenders will be held liable for payment of damages. All rights created by patent grant or registration of a utility model or design patent are reserved.

a04 Reviewed 15-Sep-04 Rikowski, SV I IS RD SW Update after re-review requested during


general review
b01 Reviewed 31-Jan-05 CJ.Bonetto – SV I IS RD PTQ Remove everything but C guidelines
b02 Released 04-Mar-05 CJ.Bonetto – SV I IS RD PTQ Rename requested during general review.
Transition to MISRA-C 20004 started (1
rule reworked, some other removed). New
template
4

Copyright © by Siemens AG 2004 For internal use only


All rights reserved 7/7 Printout from G+O portal

Anda mungkin juga menyukai