C programming standards (old)


This document is pending revision.

A few rules and recommendations remain to be added. Examples are occasionally missing. Some rules and recommendations need (further) modification for EMBOSS.

Technical terms are highlighted in green and described in the "Terminology" section at the end.

1. Overview

EMBOSS and AJAX will be written entirely in ANSI C. Coding standards are based on the Ellemtel 1992 standards for C++, adapted for C.

2. Introduction

3. General Recommendations

4. Source Code in Files

4.1 Structure of Code

4.2 Naming Files


4.4 Include Files

5. Assigning Names

6. Style

There are no rules for programming style, but there are several recommendations.

6.1 Classes

No specific rules or recommendations here, but see section 7 (Classes).

6.2 Functions

6.3 Compound Statements

6.4 Flow Control Statements

6.5 Pointers and references

6.6 Miscellanoeus

7. Classes

7.1 Considerations Regarding Access Rights

7.2 Inline Functions

Inline functions are a C++ concept which can be implemented in ANSI C as macro #defines. Using inline functions offers improved performance.

7.3 Friends

Friends are a C++ concept which can be implemented in ANSI C with the help of accessor functions not declared in the main class header file.

7.4 const Member Functions

... Needs some revision once it is clear how the C++ const definitions can be implemented in ANSI C ...

7.5 Constructors and Destructors

7.6 Assignment Operators

Assignment is the C++ implementation of newobject = oldobject and can cause various complications discussed in the Ellemtel document. The implementation of classes in ANSI C avoids these by using explicit function calls to assign objects.

7.7 Operator Overloading

In C++, operator overloading means defining functions to be called when standard operators such as "==" and "!=" are used. In ANSI C overloaded function names are implemented as explicit function calls.

7.8 Member Function Return Types

7.9 Inheritance

8. Class Templates

Perhaps some comments on the design of related objects will appear here later.

9. Functions

9.1 Function Arguments

9.2 Function Overloading

9.3 Formal Arguments

9.4 Return Types and Values

9.5 Inline Functions

"Inline functions" are a C++ concept where code is written as a function call but implemented as code directly in the source for efficiency. Fortran 77 has a similar capability with "statement functions".

9.6 Temporary Objects

9.7 General

10. Constants

11. Variables

12. Pointers

13. Type Conversions

14. Flow Control Structures

15. Expressions

16. Memory Allocation

17. Fault Handling

18. Portable Code

18.1 Data Abstraction

18.2 Sizes of Types

18.3 Type Conversions

18.4 Data Representation

18.5 Underflow and Overflow

18.6 Order of Execution

18.7 Temporary Objects

18.8 Pointer Arithmetic