[FW]C Coding Standards Quick Reference

来源:互联网 发布:淘宝首页图片 编辑:程序博客网 时间:2024/05/01 02:28

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.

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 微信提现支付密码忘记了怎么办 小米手机前置摄像头打不开怎么办 mp4视频屏幕好小怎么办 投了简历没回应怎么办 借壳上市原股票怎么办 红米note3指纹解锁失灵怎么办 来分期刷脸失败怎么办 买到假货商家不承认怎么办 买到假货翻新货工商局怎么办 三星note8笔丢了怎么办 夜跑结束后该怎么办 lol客户端正在运行中怎么办 瑞和宝终端锁定怎么办 骊爽摩托车动力弱怎么办? 换了手机跟点微信怎么办 手机送点插头换了怎么办 校园网总是显示有代理软件怎么办 电脑连接无线网络需要登录怎么办 智校园密码忘了怎么办 ivvi手机开不开机怎么办 跑鞋子大了一码怎么办 洗浴搓澡出汗多该怎么办 联华超市卡丢了怎么办 飞利浦电视的应用打不开怎么办 贵阳市下岗职工办理门面补贴怎么办 陌陌上被骗了色怎么办 七位数的座机要怎么办 开通米粉卡店铺预留电话号码怎么办 办信用卡没有单位电话怎么办 qq账号永久封停怎么办 qq号给冻结了怎么办 微信被官方封2天怎么办 天虹的卡丢了怎么办 顺丰快递到不了的地区怎么办 信用卡兑换东西超过积分怎么办 新买的冰箱坏了怎么办 买新洗衣机出现克坏怎么办 京东当日达没到达怎么办 兴隆卡不能用了怎么办 龙津时代烂尾了怎么办 三星s8电耗尽无法开机怎么办