123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
- <meta http-equiv="X-UA-Compatible" content="IE=9"/>
- <meta name="generator" content="Doxygen 1.8.17"/>
- <meta name="viewport" content="width=device-width, initial-scale=1"/>
- <title>GRPC C++: GRPC C STYLE GUIDE</title>
- <link href="tabs.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="jquery.js"></script>
- <script type="text/javascript" src="dynsections.js"></script>
- <link href="search/search.css" rel="stylesheet" type="text/css"/>
- <script type="text/javascript" src="search/searchdata.js"></script>
- <script type="text/javascript" src="search/search.js"></script>
- <link href="doxygen.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
- <div id="titlearea">
- <table cellspacing="0" cellpadding="0">
- <tbody>
- <tr style="height: 56px;">
- <td id="projectalign" style="padding-left: 0.5em;">
- <div id="projectname">GRPC C++
-  <span id="projectnumber">1.36.1</span>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- <!-- end header part -->
- <!-- Generated by Doxygen 1.8.17 -->
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- var searchBox = new SearchBox("searchBox", "search",false,'Search');
- /* @license-end */
- </script>
- <script type="text/javascript" src="menudata.js"></script>
- <script type="text/javascript" src="menu.js"></script>
- <script type="text/javascript">
- /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
- $(function() {
- initMenu('',true,false,'search.php','Search');
- $(document).ready(function() { init_search(); });
- });
- /* @license-end */</script>
- <div id="main-nav"></div>
- <!-- window showing the filter options -->
- <div id="MSearchSelectWindow"
- onmouseover="return searchBox.OnSearchSelectShow()"
- onmouseout="return searchBox.OnSearchSelectHide()"
- onkeydown="return searchBox.OnSearchSelectKey(event)">
- </div>
- <!-- iframe showing the search results (closed by default) -->
- <div id="MSearchResultsWindow">
- <iframe src="javascript:void(0)" frameborder="0"
- name="MSearchResults" id="MSearchResults">
- </iframe>
- </div>
- </div><!-- top -->
- <div class="PageDoc"><div class="header">
- <div class="headertitle">
- <div class="title">GRPC C STYLE GUIDE </div> </div>
- </div><!--header-->
- <div class="contents">
- <div class="textblock"><h1><a class="anchor" id="autotoc_md33"></a>
- Background</h1>
- <p>Here we document style rules for C usage in the gRPC Core library.</p>
- <h1><a class="anchor" id="autotoc_md34"></a>
- General</h1>
- <ul>
- <li>Layout rules are defined by clang-format, and all code should be passed through clang-format. A (docker-based) script to do so is included in <a href="../tools/distrib/clang_format_code.sh">tools/distrib/clang_format_code.sh</a>.</li>
- </ul>
- <h1><a class="anchor" id="autotoc_md35"></a>
- Header Files</h1>
- <ul>
- <li>Public header files (those in the include/grpc tree) should compile as pedantic C89.</li>
- <li>Public header files should be includable from C++ programs. That is, they should include the following: <div class="fragment"><div class="line"><span class="preprocessor">#ifdef __cplusplus</span></div>
- <div class="line"><span class="keyword">extern</span> <span class="stringliteral">"C"</span> {</div>
- <div class="line"><span class="preprocessor"># endif</span></div>
- <div class="line"> </div>
- <div class="line"><span class="comment">/* ... body of file ... */</span></div>
- <div class="line"> </div>
- <div class="line"><span class="preprocessor">#ifdef __cplusplus</span></div>
- <div class="line">}</div>
- <div class="line"><span class="preprocessor"># endif</span></div>
- </div><!-- fragment --></li>
- <li>Header files should be self-contained and end in .h.</li>
- <li><p class="startli">All header files should have a <code>#define</code> guard to prevent multiple inclusion. To guarantee uniqueness they should be based on the file's path.</p>
- <p class="startli">For public headers: <code><a class="el" href="grpc_8h.html">include/grpc/grpc.h</a></code> → <code>GRPC_GRPC_H</code></p>
- <p class="startli">For private headers: <code>src/core/lib/channel/channel_stack.h</code> → <code>GRPC_CORE_LIB_CHANNEL_CHANNEL_STACK_H</code></p>
- </li>
- </ul>
- <h1><a class="anchor" id="autotoc_md36"></a>
- Variable Initialization</h1>
- <p>When declaring a (non-static) pointer variable, always initialize it to <code>NULL</code>. Even in the case of static pointer variables, it's recommended to explicitly initialize them to <code>NULL</code>.</p>
- <h1><a class="anchor" id="autotoc_md37"></a>
- C99 Features</h1>
- <ul>
- <li>Variable sized arrays are not allowed.</li>
- <li>Do not use the 'inline' keyword.</li>
- <li>Flexible array members are allowed (<a href="https://en.wikipedia.org/wiki/Flexible_array_member">https://en.wikipedia.org/wiki/Flexible_array_member</a>).</li>
- </ul>
- <h1><a class="anchor" id="autotoc_md38"></a>
- Comments</h1>
- <p>Within public header files, only <code>/* */</code> comments are allowed.</p>
- <p>Within implementation files and private headers, either single line <code>//</code> or multi line <code>/* */</code> comments are allowed. Only one comment style per file is allowed however (i.e. if single line comments are used anywhere within a file, ALL comments within that file must be single line comments).</p>
- <h1><a class="anchor" id="autotoc_md39"></a>
- Symbol Names</h1>
- <ul>
- <li>Non-static functions must be prefixed by <code>grpc_</code></li>
- <li>Static functions must <em>not</em> be prefixed by <code>grpc_</code></li>
- <li>Typenames of <code>struct</code>s , <code>union</code>s, and <code>enum</code>s must be prefixed by <code>grpc_</code> if they are declared in a header file. They must not be prefixed by <code>grpc_</code> if they are declared in a source file.</li>
- <li>Enumeration values and <code>#define</code> names must be uppercase. All other values must be lowercase.</li>
- <li>Enumeration values or <code>#define</code> names defined in a header file must be prefixed with <code>GRPC_</code> (except for <code>#define</code> macros that are being used to substitute functions; those should follow the general rules for functions). Enumeration values or <code>#define</code>s defined in source files must not be prefixed with <code>GRPC_</code>.</li>
- <li>Multiple word identifiers use underscore as a delimiter, <em>never</em> camel case. E.g. <code>variable_name</code>.</li>
- </ul>
- <h1><a class="anchor" id="autotoc_md40"></a>
- Functions</h1>
- <ul>
- <li>The use of <a href="http://man7.org/linux/man-pages/man3/atexit.3.html"><code>atexit()</code></a> is in forbidden in libgrpc. </li>
- </ul>
- </div></div><!-- contents -->
- </div><!-- PageDoc -->
- <!-- start footer part -->
- <hr class="footer"/><address class="footer"><small>
- Generated on Wed Mar 3 2021 19:17:22 for GRPC C++ by  <a href="http://www.doxygen.org/index.html">
- <img class="footer" src="doxygen.png" alt="doxygen"/>
- </a> 1.8.17
- </small></address>
- </body>
- </html>
|