日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

GNU的C++代码书写规范

發布時間:2023/12/14 c/c++ 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GNU的C++代码书写规范 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
GNU的C++代碼書寫規范,C語言之父Dennis Ritchie親自修訂

C++ Standard Library Style Guidelines ?DRAFT 1999-02-26
-------------------------------------

This library is written to appropriate C++ coding standards. ?As such,
it is intended to precede the recommendations of the GNU Coding
Standard, which can be referenced here:

http://www.gnu.ai.mit.edu/prep/standards_toc.html

ChangeLog entries for member functions should use the
classname::member function name syntax as follows:

1999-04-15 ?Dennis Ritchie ?<dr@att.com>

* src/basic_file.cc (__basic_file::open): Fix thinko in
_G_HAVE_IO_FILE_OPEN bits.

Notable areas of divergence from what may be previous local practice
(particularly for GNU C) include:

01. Pointers and references
?char* p = "flop";
?char& c = *p;
? ? -NOT-
?char *p = "flop"; ?// wrong
?char &c = *p; ? ? ?// wrong
?
? ?Reason: In C++, definitions are mixed with executable code. ?Here, ? ? ?
? ?p ? ? ? ? ?is being initialized, not *p. ?This is near-universal
? ? ? ? ? ?practice among C++ programmers; it is normal for C hackers
? ? ? ? ? ?to switch spontaneously as they gain experience.

02. Operator names and parentheses
?operator==(type)
? ? -NOT-
?operator == (type) ?// wrong
? ?
? ?Reason: The == is part of the function name. ?Separating
? ? ? ? ? ?it makes the declaration look like an expression.

03. Function names and parentheses
?void mangle()
? ? -NOT-
?void mangle () ?// wrong

? ? Reason: no space before parentheses (except after a control-flow
? ? keyword) is near-universal practice for C++. ?It identifies the
? ? parentheses as the function-call operator or declarator, as
? ? opposed to an expression or other overloaded use of parentheses.

04. Template function indentation
?template<typename T>
? ?void
? ?template_function(args)
? ?{ }
? ? ?-NOT-
?template<class T>
?void template_function(args) { };
?
? ? Reason: In class definitions, without indentation whitespace is
? ? ? ? ? ? needed both above and below the declaration to distinguish
? ? it visually from other members. ?(Also, re: "typename"
? ? rather than "class".) ?T often could be int, which is
? ? not a class. ?("class", here, is an anachronism.)

05. Template class indentation
?template<typename _CharT, typename _Traits>
? ?class basic_ios : public ios_base
? ?{
? ?public:
? ? ?// Types:
? ? };
?-NOT-
?template<class _CharT, class _Traits>
?class basic_ios : public ios_base
? ?{
? ?public:
? ? ?// Types:
? ? };
?-NOT-
?template<class _CharT, class _Traits>
? ?class basic_ios : public ios_base
?{
? ?public:
? ? ?// Types:
? };

06. Enumerators
?enum
?{
? ?space = _ISspace,
? ?print = _ISprint,
? ?cntrl = _IScntrl,
? };
?-NOT-
?enum { space = _ISspace, print = _ISprint, cntrl = _IScntrl };

07. Member initialization lists
? All one line, separate from class name.

?gribble::gribble()
?: _M_private_data(0), _M_more_stuff(0), _M_helper(0);
?{ }
?-NOT-
?gribble::gribble() : _M_private_data(0), _M_more_stuff(0), _M_helper(0);
?{ }

08. Try/Catch blocks
?try {
? ?//
? } ?
?catch(...) {
? ?//
? } ?
?-NOT-
?try { // } catch(...) { // }

09. Member functions declarations and defintions
? Keywords such as extern, static, export, explicit, inline, etc
? go on the line above the function name. Thus

?virtual int ?
?foo()
?-NOT-
?virtual int foo()

Reason: GNU coding conventions dictate return types for functions
? ? are on a separate line than the function name and parameter list
? ? for definitions. For C++, where we have member functions that can
. ? ?be either inline definitions or declarations, keeping to this
? ? standard allows all member function names for a given class to be
aligned to the same margin, increasing readibility.


10. Invocation of member functions with "this->"
? For non-uglified names, use this->name to call the function.

?this->sync()
?-NOT-
?sync()

The library currently has a mixture of GNU-C and modern C++ coding
styles. ?The GNU C usages will be combed out gradually.

Name patterns:

For nonstandard names appearing in Standard headers, we are constrained
to use names that begin with underscores. ?This is called "uglification".
The convention is:

?Local and argument names: ?__[a-z].*

? ?Examples: ?__count ?__ix ?__s1 ?

?Type names and template formal-argument names: _[A-Z][^_].*

? ?Examples: ?_Helper ?_CharT ?_N

?Member data and function names: _M_.*

? ?Examples: ?_M_num_elements ?_M_initialize ()

?Static data members, constants, and enumerations: _S_.*

? ?Examples: _S_max_elements ?_S_default_value

Don't use names in the same scope that differ only in the prefix,
e.g. _S_top and _M_top. ?See BADNAMES for a list of forbidden names.
(The most tempting of these seem to be and "_T" and "__sz".)

Names must never have "__" internally; it would confuse name
unmanglers on some targets. ?Also, never use "__[0-9]", same reason.

--------------------------

[BY EXAMPLE]
? ?
#ifndef ?_HEADER_
#define ?_HEADER_ 1

namespace std
{
?class gribble
?{
?public:
? ?// ctor, op=, dtor
? ?gribble() throw();

? ?gribble(const gribble&);

? ?explicit
? ?gribble(int __howmany);

? ?gribble&
? ?operator=(const gribble&);

? ?virtual
? ?~gribble() throw ();

? ?// argument
? ?inline void ?
? ?public_member(const char* __arg) const;

? ?// in-class function definitions should be restricted to one-liners.
? ?int
? ?one_line() { return 0 }

? ?int
? ?two_lines(const char* arg)
? ? ?{ return strchr(arg, 'a'); }

? ?inline int
? ?three_lines(); ?// inline, but defined below.

? ?// note indentation
? ?template<typename _Formal_argument>
? ? ?void
? ? ?public_template() const throw();

? ?template<typename _Iterator>
? ? ?void
? ? ?other_template();

?private:
? ?class _Helper;

? ?int _M_private_data;
? ?int _M_more_stuff;
? ?_Helper* _M_helper;
? ?int _M_private_function();

? ?enum _Enum
? ? ?{
_S_one,
_S_two
? ? ? };

? ?static void
? ?_S_initialize_library();
? };

// More-or-less-standard language features described by lack, not presence:
# ifndef _G_NO_LONGLONG
?extern long long _G_global_with_a_good_long_name; ?// avoid globals!
# endif

?// avoid in-class inline definitions, define separately;
?// ? likewise for member class definitions:
?inline int
?gribble::public_member() const
?{ int __local = 0; return __local; }

?class gribble::_Helper
?{
? ?int _M_stuff;

? ?friend class gribble;
? };
}

// Names beginning with "__": only for arguments and
// ? local variables; never use "__" in a type name, or
// ? within any name; never use "__[0-9]".

#endif /* _HEADER_ */


namespace std {

?template<typename T> ?// notice: "typename", not "class", no space
? ?long_return_value_type<with_many, args> ?
? ?function_name(char* pointer, ? ? ? ? ? ? ? // "char *pointer" is wrong.
?char* argument,
?const Reference& ref)
? ?{
? ? ?// int a_local; ?/* wrong; see below. */
? ? ?if (test)
? ? ?{
?nested code
? ? ? }
? ?
? ? ?int a_local = 0; ?// declare variable at first use.

? ? ?// ?char a, b, *p; ? /* wrong */
? ? ?char a = 'a';
? ? ?char b = a + 1;
? ? ?char* c = "abc"; ?// each variable goes on its own line, always.

? ? ?// except maybe here...
? ? ?for (unsigned i = 0, mask = 1; mask; ++i, mask <<= 1) {
?// ...
? ? ? }
? ? }
?
?gribble::gribble()
?: _M_private_data(0), _M_more_stuff(0), _M_helper(0);
?{ }

?inline int
?gribble::three_lines()
?{
? ?// doesn't fit in one line.
? }

}

總結

以上是生活随笔為你收集整理的GNU的C++代码书写规范的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 麻豆免费视频 | 最好看的2018中文2019 | www.国产欧美 | 婷婷开心激情网 | 尤物193.com | 久久久久久久偷拍 | 在线视频中文字幕 | 欧美特级aaa | 免费成人福利视频 | 精品三级电影 | 在线观看h网站 | 91精品国产色综合久久不卡电影 | 国产精品高潮呻吟久久av野狼 | 亚洲成人av在线播放 | 光棍影院手机版在线观看免费 | 欧美高清一区 | 激情久久婷婷 | 日韩一卡 | 男人的亚洲天堂 | 暗呦丨小u女国产精品 | 亚洲男人的天堂网站 | 国产亚洲欧美一区二区三区 | 寡妇高潮一级视频免费看 | 超碰操| 一级二级在线观看 | 台湾a级片| 人妖videosex高潮另类 | 久久人人添人人爽添人人片 | 国产视频一区三区 | 国产精品久久久久久久久久久久久久久久久久 | 国产aⅴ | 呦呦网 | 欧美做爰xxxⅹ性欧美大片 | 久草a在线 | 中日韩在线观看视频 | 宇都宫紫苑在线播放 | 国产在线不卡 | 狠狠av| 四虎影视网 | 91搞| 亚洲欧美中日韩 | 国产精品久久一区二区三区动 | 麻豆爱爱| 亚洲无av | 九九影院最新理论片 | 亚欧精品视频一区二区三区 | 中文字幕在线观看亚洲 | 人妻熟人中文字幕一区二区 | 亚洲精品aⅴ | 日本一区二区三区免费电影 | youjizz亚洲| 日日夜夜噜 | 裸体视频软件 | 91亚瑟视频 | 女生下面流水视频 | 色婷婷视频网 | 黄色一级在线视频 | 韩国欧美三级 | 国产精品人妻一区二区三区 | 亚洲av永久无码精品一百度影院 | 国产一区不卡在线观看 | 香港三日本8a三级少妇三级99 | 波多野结衣绝顶大高潮 | 色呦呦在线免费观看 | 亚洲老老头同性老头交j | 性欧美丰满熟妇xxxx性仙踪林 | 成人69视频 | 色资源av | 六月婷婷综合网 | 日韩av手机在线免费观看 | 91插插插影库永久免费 | 99中文字幕在线观看 | 黑人欧美一区二区三区 | 日本精品在线观看 | www.欧美亚洲 | julia一区二区三区中文字幕 | 色屁屁一区二区三区视频 | www.久久成人 | 韩国三级做爰视频 | 国产成人精品在线视频 | 日韩精品人妻一区二区三区免费 | 亚洲欧洲综合 | 看毛片视频 | 日日夜夜操av | 久久国产经典 | 亚洲男人天堂久久 | 一级全黄少妇性色生活片 | 成人日皮视频 | 黄频视频在线观看 | 女生和男生一起插插插 | 色天天综合| av手机网站 | 相亲对象是问题学生在线观看 | 欧美私人情侣网站 | av资源吧首页 | 一区二区三区资源 | 在线激情网| 韩国av一区二区 | 成人深夜福利 |