md_doc_c-style-guide.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.6"/>
  7. <title>GRPC C++: GRPC C STYLE GUIDE</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="search/search.js"></script>
  13. <script type="text/javascript">
  14. $(document).ready(function() { searchBox.OnSelectItem(0); });
  15. </script>
  16. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  17. </head>
  18. <body>
  19. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  20. <div id="titlearea">
  21. <table cellspacing="0" cellpadding="0">
  22. <tbody>
  23. <tr style="height: 56px;">
  24. <td style="padding-left: 0.5em;">
  25. <div id="projectname">GRPC C++
  26. &#160;<span id="projectnumber">1.3.0</span>
  27. </div>
  28. </td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </div>
  33. <!-- end header part -->
  34. <!-- Generated by Doxygen 1.8.6 -->
  35. <script type="text/javascript">
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. </script>
  38. <div id="navrow1" class="tabs">
  39. <ul class="tablist">
  40. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  41. <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  42. <li><a href="modules.html"><span>Modules</span></a></li>
  43. <li><a href="namespaces.html"><span>Namespaces</span></a></li>
  44. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  45. <li><a href="files.html"><span>Files</span></a></li>
  46. <li>
  47. <div id="MSearchBox" class="MSearchBoxInactive">
  48. <span class="left">
  49. <img id="MSearchSelect" src="search/mag_sel.png"
  50. onmouseover="return searchBox.OnSearchSelectShow()"
  51. onmouseout="return searchBox.OnSearchSelectHide()"
  52. alt=""/>
  53. <input type="text" id="MSearchField" value="Search" accesskey="S"
  54. onfocus="searchBox.OnSearchFieldFocus(true)"
  55. onblur="searchBox.OnSearchFieldFocus(false)"
  56. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  57. </span><span class="right">
  58. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  59. </span>
  60. </div>
  61. </li>
  62. </ul>
  63. </div>
  64. <!-- window showing the filter options -->
  65. <div id="MSearchSelectWindow"
  66. onmouseover="return searchBox.OnSearchSelectShow()"
  67. onmouseout="return searchBox.OnSearchSelectHide()"
  68. onkeydown="return searchBox.OnSearchSelectKey(event)">
  69. <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(11)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(12)"><span class="SelectionMark">&#160;</span>Pages</a></div>
  70. <!-- iframe showing the search results (closed by default) -->
  71. <div id="MSearchResultsWindow">
  72. <iframe src="javascript:void(0)" frameborder="0"
  73. name="MSearchResults" id="MSearchResults">
  74. </iframe>
  75. </div>
  76. </div><!-- top -->
  77. <div class="header">
  78. <div class="headertitle">
  79. <div class="title">GRPC C STYLE GUIDE </div> </div>
  80. </div><!--header-->
  81. <div class="contents">
  82. <div class="textblock"><h2>Background </h2>
  83. <p>Here we document style rules for C usage in the gRPC Core library.</p>
  84. <h2>General </h2>
  85. <ul>
  86. <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>
  87. </ul>
  88. <h2>Header Files </h2>
  89. <ul>
  90. <li>Public header files (those in the include/grpc tree) should compile as pedantic C89.</li>
  91. <li>Public header files should be includable from C++ programs. That is, they should include the following: ```c #ifdef __cplusplus extern "C" { <h1>endif</h1>
  92. </li>
  93. </ul>
  94. <p>/* ... body of file ...</p>
  95. <p>#ifdef __cplusplus } </p>
  96. <h1>endif</h1>
  97. <p>```</p>
  98. <ul>
  99. <li>Header files should be self-contained and end in .h.</li>
  100. <li><p class="startli">All header files should have a #define guard to prevent multiple inclusion. To guarantee uniqueness they should be based on the file's path.</p>
  101. <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>
  102. <p class="startli">For private headers: <code>src/core/channel/channel_stack.h</code> → <code>GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_STACK_H</code></p>
  103. </li>
  104. </ul>
  105. <h2>Variable Initialization </h2>
  106. <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>
  107. <h2>C99 Features </h2>
  108. <ul>
  109. <li>Variable sized arrays are not allowed.</li>
  110. <li>Do not use the 'inline' keyword.</li>
  111. <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>
  112. </ul>
  113. <h2>Comments </h2>
  114. <p>Within public header files, only <code>/*</code> comments are allowed.</p>
  115. <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>
  116. <h2>Symbol Names </h2>
  117. <ul>
  118. <li>Non-static functions must be prefixed by <code>grpc_</code></li>
  119. <li>Static functions must <em>not</em> be prefixed by <code>grpc_</code></li>
  120. <li>Enumeration values and <code>#define</code> names must be uppercase. All other values must be lowercase.</li>
  121. <li>Multiple word identifiers use underscore as a delimiter, <em>never</em> camel case. E.g. <code>variable_name</code>.</li>
  122. </ul>
  123. <h2>Functions </h2>
  124. <ul>
  125. <li>The use of <a href="http://man7.org/linux/man-pages/man3/atexit.3.html">`atexit()`</a> is in forbidden in libgrpc. </li>
  126. </ul>
  127. </div></div><!-- contents -->
  128. <!-- start footer part -->
  129. <hr class="footer"/><address class="footer"><small>
  130. Generated on Thu Apr 27 2017 17:26:13 for GRPC C++ by &#160;<a href="http://www.doxygen.org/index.html">
  131. <img class="footer" src="doxygen.png" alt="doxygen"/>
  132. </a> 1.8.6
  133. </small></address>
  134. </body>
  135. </html>