ImageVerifierCode 换一换
格式:DOC , 页数:14 ,大小:36.26KB ,
资源ID:7948693      下载积分:10 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/7948693.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(Google的C--编码规范.doc)为本站上传会员【仙人****88】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

Google的C--编码规范.doc

1、Google C++ Style Guide Revision 3.180 Benjy Weinberger Craig Silverstein Gregory Eitzmann Mark Mentovai Tashana Landray Each style point has a summary for which additional information is available by toggling the accompanying arrow button that looks this way:▶. You may toggle all summaries wi

2、th the big arrow button: ▶ Toggle all summaries Table of Contents Header Files The #define Guard Header File Dependencies Inline Functions The -inl.h FilesFunction Parameter Ordering Names and Order of Includes Scoping Namespaces Nested Classes Nonmember, Static Member, and Global Functions Lo

3、cal VariablesStatic and Global Variables Classes Doing Work in Constructors Default Constructors Explicit Constructors Copy ConstructorsStructs vs. Classes Inheritance Multiple Inheritance Interfaces Operator OverloadingAccess Control Declaration Order Write Short Functions Google-Specific Magic

4、 Smart Pointers cpplint Other C++ Features Reference Arguments Function Overloading Default Arguments Variable-Length Arrays and alloca()Friends Exceptions Run-Time Type Information (RTTI) Casting StreamsPreincrement and Predecrement Use of const Integer Types 64-bit Portability Preprocessor Macro

5、s0 and NULL sizeof Boost C++0x Naming General Naming Rules File Names Type Names Variable Names Constant Names Function NamesNamespace Names Enumerator Names Macro Names Exceptions to Naming Rules Comments Comment Style File Comments Class Comments Function Comments Variable CommentsImplementati

6、on Comments Punctuation, Spelling and Grammar TODO Comments Deprecation Comments Formatting Line Length Non-ASCII Characters Spaces vs. Tabs Function Declarations and DefinitionsFunction Calls Conditionals Loops and Switch Statements Pointer and Reference ExpressionsBoolean Expressions Return Valu

7、es Variable and Array Initialization Preprocessor DirectivesClass Format Constructor Initializer Lists Namespace Formatting Horizontal WhitespaceVertical Whitespace Exceptions to the Rules Existing Non-conformant Code Windows Code Important Note Displaying Hidden Details in this Guide ▶ This s

8、tyle guide contains many details that are initially hidden from view. They are marked by the triangle icon, which you see here on your left. Click it now. You should see "Hooray" appear below. Background C++ is the main development language used by many of Google's open-source projects. As every C

9、 programmer knows, the language has many powerful features, but this power brings with it complexity, which in turn can make code more bug-prone and harder to read and maintain. The goal of this guide is to manage this complexity by describing in detail the dos and don'ts of writing C++ code. The

10、se rules exist to keep the code base manageable while still allowing coders to use C++ language features productively. Style, also known as readability, is what we call the conventions that govern our C++ code. The term Style is a bit of a misnomer, since these conventions cover far more than just

11、source file formatting. One way in which we keep the code base manageable is by enforcing consistency. It is very important that any programmer be able to look at another's code and quickly understand it. Maintaining a uniform style and following conventions means that we can more easily use "patte

12、rn-matching" to infer what various symbols are and what invariants are true about them. Creating common, required idioms and patterns makes code much easier to understand. In some cases there might be good arguments for changing certain style rules, but we nonetheless keep things as they are in orde

13、r to preserve consistency. Another issue this guide addresses is that of C++ feature bloat. C++ is a huge language with many advanced features. In some cases we constrain, or even ban, use of certain features. We do this to keep code simple and to avoid the various common errors and problems that t

14、hese features can cause. This guide lists these features and explains why their use is restricted. Open-source projects developed by Google conform to the requirements in this guide. Note that this guide is not a C++ tutorial: we assume that the reader is familiar with the language. Header Files

15、 In general, every .cc file should have an associated .h file. There are some common exceptions, such as unittests and small.cc files containing just a main() function. Correct use of header files can make a huge difference to the readability, size and performance of your code. The following rules

16、 will guide you through the various pitfalls of using header files. The #define Guard ▶ All header files should have #define guards to prevent multiple inclusion. The format of the symbol name should be___H_. Header File Dependencies ▶ Don't use an #include when a forward

17、declaration would suffice. Inline Functions ▶ Define functions inline only when they are small, say, 10 lines or less. The -inl.h Files ▶ You may use file names with a -inl.h suffix to define complex inline functions when needed. Function Parameter Ordering ▶ When defining a function, param

18、eter order is: inputs, then outputs. Names and Order of Includes ▶ Use standard order for readability and to avoid hidden dependencies: C library, C++ library, other libraries' .h, your project's .h. Scoping Namespaces ▶ Unnamed namespaces in .cc files are encouraged. With named namespaces, c

19、hoose the name based on the project, and possibly its path. Do not use a using-directive. Nested Classes ▶ Although you may use public nested classes when they are part of an interface, consider a namespace to keep declarations out of the global scope. Nonmember, Static Member, and Global Functi

20、ons ▶ Prefer nonmember functions within a namespace or static member functions to global functions; use completely global functions rarely. Local Variables ▶ Place a function's variables in the narrowest scope possible, and initialize variables in the declaration. Static and Global Variables

21、▶ Static or global variables of class type are forbidden: they cause hard-to-find bugs due to indeterminate order of construction and destruction. Classes Classes are the fundamental unit of code in C++. Naturally, we use them extensively. This section lists the main dos and don'ts you should fol

22、low when writing a class. Doing Work in Constructors ▶ In general, constructors should merely set member variables to their initial values. Any complex initialization should go in an explicit Init() method. Default Constructors ▶ You must define a default constructor if your class defines memb

23、er variables and has no other constructors. Otherwise the compiler will do it for you, badly. Explicit Constructors ▶ Use the C++ keyword explicit for constructors with one argument. Copy Constructors ▶ Provide a copy constructor and assignment operator only when necessary. Otherwise, disable

24、them withDISALLOW_COPY_AND_ASSIGN. Structs vs. Classes ▶ Use a struct only for passive objects that carry data; everything else is a class. Inheritance ▶ Composition is often more appropriate than inheritance. When using inheritance, make it public. Multiple Inheritance ▶ Only very rarely i

25、s multiple implementation inheritance actually useful. We allow multiple inheritance only when at most one of the base classes has an implementation; all other base classes must be pure interface classes tagged with theInterface suffix. Interfaces ▶ Classes that satisfy certain conditions are all

26、owed, but not required, to end with an Interface suffix. Operator Overloading ▶ Do not overload operators except in rare, special circumstances. Access Control ▶ Make data members private, and provide access to them through accessor functions as needed (for technical reasons, we allow data mem

27、bers of a test fixture class to be protected when using Google Test). Typically a variable would be calledfoo_ and the accessor function foo(). You may also want a mutator function set_foo(). Exception: static const data members (typically called kFoo) need not be private. Declaration Order ▶ Use

28、 the specified order of declarations within a class: public: before private:, methods before data members (variables), etc. Write Short Functions ▶ Prefer small and focused functions. Google-Specific Magic There are various tricks and utilities that we use to make C++ code more robust, and vari

29、ous ways we use C++ that may differ from what you see elsewhere. Smart Pointers ▶ If you actually need pointer semantics, scoped_ptr is great. You should only use std::tr1::shared_ptr under very specific conditions, such as when objects need to be held by STL containers. You should never use auto

30、ptr. cpplint ▶ Use cpplint.py to detect style errors. Other C++ Features Reference Arguments ▶ All parameters passed by reference must be labeled const. Function Overloading ▶ Use overloaded functions (including constructors) only if a reader looking at a call site can get a good idea of

31、what is happening without having to first figure out exactly which overload is being called. Default Arguments ▶ We do not allow default function parameters, except in a few uncommon situations explained below. Variable-Length Arrays and alloca() ▶ We do not allow variable-length arrays or all

32、oca(). Friends ▶ We allow use of friend classes and functions, within reason. Exceptions ▶ We do not use C++ exceptions. Run-Time Type Information (RTTI) ▶ We do not use Run Time Type Information (RTTI). Casting ▶ Use C++ casts like static_cast<>(). Do not use other cast formats like int

33、 y = (int)x; or int y = int(x);. Streams ▶ Use streams only for logging. Preincrement and Predecrement ▶ Use prefix form (++i) of the increment and decrement operators with iterators and other template objects. Use of const ▶ We strongly recommend that you use const whenever it makes sense

34、to do so. Integer Types ▶ Of the built-in C++ integer types, the only one used is int. If a program needs a variable of a different size, use a precise-width integer type from , such as int16_t. 64-bit Portability ▶ Code should be 64-bit and 32-bit friendly. Bear in mind problems of

35、printing, comparisons, and structure alignment. Preprocessor Macros ▶ Be very cautious with macros. Prefer inline functions, enums, and const variables to macros. 0 and NULL ▶ Use 0 for integers, 0.0 for reals, NULL for pointers, and '\0' for chars. sizeof ▶ Use sizeof(varname) instead of s

36、izeof(type) whenever possible. Boost ▶ Use only approved libraries from the Boost library collection. C++0x ▶ Use only approved libraries and language extensions from C++0x. Currently, none are approved. Naming The most important consistency rules are those that govern naming. The style of a

37、 name immediately informs us what sort of thing the named entity is: a type, a variable, a function, a constant, a macro, etc., without requiring us to search for the declaration of that entity. The pattern-matching engine in our brains relies a great deal on these naming rules. Naming rules are pr

38、etty arbitrary, but we feel that consistency is more important than individual preferences in this area, so regardless of whether you find them sensible or not, the rules are the rules. General Naming Rules ▶ Function names, variable names, and filenames should be descriptive; eschew abbreviation

39、 Types and variables should be nouns, while functions should be "command" verbs. File Names ▶ Filenames should be all lowercase and can include underscores (_) or dashes (-). Follow the convention that your project uses. If there is no consistent local pattern to follow, prefer "_". Type Names

40、 ▶ Type names start with a capital letter and have a capital letter for each new word, with no underscores: MyExcitingClass,MyExcitingEnum. Variable Names ▶ Variable names are all lowercase, with underscores between words. Class member variables have trailing underscores. For instance: my_exciti

41、ng_local_variable, my_exciting_member_variable_. Constant Names ▶ Use a k followed by mixed case: kDaysInAWeek. Function Names ▶ Regular functions have mixed case; accessors and mutators match the name of the variable: MyExcitingFunction(),MyExcitingMethod(), my_exciting_member_variable(), set

42、my_exciting_member_variable(). Namespace Names ▶ Namespace names are all lower-case, and based on project names and possibly their directory structure:google_awesome_project. Enumerator Names ▶ Enumerators should be named either like constants or like macros: either kEnumName or ENUM_NAME. M

43、acro Names ▶ You're not really going to define a macro, are you? If you do, they're like this: MY_MACRO_THAT_SCARES_SMALL_CHILDREN. Exceptions to Naming Rules ▶ If you are naming something that is analogous to an existing C or C++ entity then you can follow the existing naming convention scheme

44、 Comments Though a pain to write, comments are absolutely vital to keeping our code readable. The following rules describe what you should comment and where. But remember: while comments are very important, the best code is self-documenting. Giving sensible names to types and variables is much be

45、tter than using obscure names that you must then explain through comments. When writing your comments, write for your audience: the next contributor who will need to understand your code. Be generous — the next one may be you! Comment Style ▶ Use either the // or /* */ syntax, as long as you are

46、 consistent. File Comments ▶ Start each file with a copyright notice, followed by a description of the contents of the file. Class Comments ▶ Every class definition should have an accompanying comment that describes what it is for and how it should be used. Function Comments ▶ Declaration c

47、omments describe use of the function; comments at the definition of a function describe operation. Variable Comments ▶ In general the actual name of the variable should be descriptive enough to give a good idea of what the variable is used for. In certain cases, more comments are required. Imple

48、mentation Comments ▶ In your implementation you should have comments in tricky, non-obvious, interesting, or important parts of your code. Punctuation, Spelling and Grammar ▶ Pay attention to punctuation, spelling, and grammar; it is easier to read well-written comments than badly written ones.

49、 TODO Comments ▶ Use TODO comments for code that is temporary, a short-term solution, or good-enough but not perfect. Deprecation Comments ▶ Mark deprecated interface points with DEPRECATED comments. Formatting Coding style and formatting are pretty arbitrary, but a project is much easier to

50、 follow if everyone uses the same style. Individuals may not agree with every aspect of the formatting rules, and some of the rules may take some getting used to, but it is important that all project contributors follow the style rules so that they can all read and understand everyone's code easily.

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服