分享
 
 
 

[FW]C Coding Standards Quick Reference

王朝other·作者佚名  2006-02-01
窄屏简体版  字體: |||超大  

Wireless Systems Group

C Coding Standards Quick Reference

Comments 3.1

Every file that contains source code shall be documented with an introductory comment that provides information on the file name, its contents, and copyright information.

Every file that contains source code shall contain a revision history.

Files containing more that one function shall contain a function header for each function describing the function.

Code shall not be commented out.

Comments shall not be nested.

Constants 3.2

Constants shall be used instead of hard coded numbers.

All locally defined constants shall be defined before the first function in the file.

If TRUE and FALSE are to be defined, TRUE shall be 1 and FALSE shall be 0.

NULL shall only be used for pointer comparisons and initializations.

Expressions 3.3

Implicit logic tests shall be avoided.

All conditional expressions shall be explicit.

Float values shall not be tested for equality.

When checking a value for equality to a constant value, the constant should be on the left-hand side of the expression.

Unsigned variables shall be used for all bit-manipulation operations.

Flow Control Statements 3.4

The code following a case label shall be terminated by a break statement.

A ‘switch’ statement shall contain a ‘default’ branch that handles unexpected cases.

A “goto” statement shall never be used.

A null statement as body of a loop shall include a comment to make the intent clear.

Functions 3.5

A function shall be no longer than 100 NCSL.

A return type of a function shall always be explicitly specified.

A function shall never return a reference or a pointer to a local variable.

Functions that return pointers shall return a NULL on a failure condition.

If a function can fail, the function shall return a status indicating a failure.

Declaring the magnitude of a single dimensional array in an argument declaration shall not be used.

A main function shall return a value indication the completion status.

Structures shall not be passed as arguments to functions and functions shall not return structures.

The const modifier shall be used in the parameter list for all parameters which are not changed by the function.

General Coding Practices 3.6

All source code shall use the POPI classification Motorola Confidential Proprietary.

Inline assembly shall not be used.

Include Files 3.7

Every include file shall contain a mechanism that prevents multiple inclusions of the file.

All #include directives shall be placed at the top of the file, just below the introductory comments and revision history.

Macros 3.8

Arguments to macros shall not produce side-effects to the arguments themselves.

Macro parameters shall be fully parenthesized. The entire macro shall also be enclosed in parenthesis.

Macros shall not be used to change the nature of the language.

A macro that produces executable code shall be written as a parameterized macro, even if no parameters are needed.

Naming Convention 3.9

All identifier name lengths shall be less than or equal to 31 characters.

Legal identifier name values shall be those specified by the ANSI C standard.

Underscore shall not be used as the first character of an identifier.

Consistent variable naming conventions shall be used.

Variables 3.10

All variable declarations shall include data types.

Every variable that is declared shall be given a value before it is used.

The size of the least significant (rightmost) dimension of an externally declared array variable shall not be specified.

An externally declared array variable shall never be declared as a pointer.

Use “void *” (or VOID *) instead of “char *” to represent a generic pointer.

Type conversions shall be explicitly cast.

Classes 4.1

The public, protected, and private sections of a class shall be declared once in the order listed.

Member functions shall not be defined within the class declaration.

Member data in a class shall be declared private, except for static constant data.

A member function that does not affect the state of an object is to be declared const.

All classes shall declare a copy constructor.

A copy constructor of a derived class shall call the copy constructor of its base class.

A class which uses “new” to allocate instances managed by a class shall define a destructor which deallocates the memory.

All classes which are used as base classes shall define a virtual destructor.

The constructors of an abstract class shall be declared as protected.

A class’ virtual functions shall not be called from within its constructors.

An initializer shall not call member functions

All classes shall declare an assignment operator.

All assignment operators shall guard against performing the action on itself.

An assignment operator of a derived class shall call the assignment operator of its base class.

Comments 4.2

Every file that contains source code shall be documented with an introductory comment that provides information on the file name, its contents, and copyright information.

Every file that contains source code shall contain a revision history.

Files containing more that one function shall contain a function header for each function.

Code shall not be commented out.

Comments shall not be nested.

Constants 4.3

const shall be used instead of #define.

NULL shall not be used.

Constants shall be used instead of hard coded numbers.

Exceptions 4.4

Classes shall be used to represent exceptions.

Destructors shall prevent exceptions from escaping.

Exceptions shall be caught by reference.

Expressions 4.5

Assumption about any particular expression evaluation order shall be avoided.

Implicit logic tests shall be avoided.

All conditional expressions shall be explicit.

Float values shall not be tested for equality.

Flow Control Statements 4.6

The code following a case label shall be terminated by a break statement.

A ‘switch’ statement shall contain a ‘default’ branch that handles unexpected cases in an appropriate way.

A “goto” statement shall never be used.

A null statement as body of a loop shall include a comment to make the intent clear.

Functions 4.7

A function shall be no longer than 100 NCSL.

A return type of a function shall always be explicitly specified.

A function shall never return a reference or a pointer to a local, private or protected variable.

If a function can fail, the function shall return a status indicating a failure or throw an exception.

Functions (cont.)

Functions that return pointers shall return 0 or throw an exception on a failure condition.

A main function shall return a value indication the completion status.

The magnitude of a single dimensional array in an argument declaration shall not be used.

The preprocessor directive #define shall not be used to obtain more efficient code; instead, inline functions shall be used.

One line accessor and modifier functions (e.g. getValue, setValue) shall be inline.

General Coding Practices 4.8

All source code shall use the POPI classification Motorola Confidential Proprietary.

Inline assembly shall not be used.

Include Files 4.9

Only one class shall be declared per header file.

Every include file shall contain a mechanism that prevents multiple inclusions of the file.

Header files shall be self sufficient.

Memory Allocation 4.10

Malloc, realloc and free shall not be used.

Empty brackets ("[]") shall be provided for delete when deallocating arrays.

Naming Convention 4.11

Legal identifier name values shall be those specified by the ANSI C++ standard.

Consistent naming conventions shall be used.

Type Conversion 4.12

C++ style casts shall be used instead of C style.

Variables 4.13

Every variable that is declared shall be given a value before it is used.

The size of the least significant (rightmost) dimension of an externally declared array variable shall not be specified.

Type conversions shall be explicitly cast.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有