<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <channel>
        <title>CUBRID Coding Conventions</title>
        <link>http://www.cubrid.org/?mid=coding_conventions</link>
        <description>CUBRID Coding Conventions</description>
        <language>en</language>
        <pubDate>Fri, 09 Apr 2010 12:56:42 -0800</pubDate>
        <lastBuildDate>Wed, 19 Oct 2011 23:16:35 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>CUBRID Coding Conventions</title>
            <dc:creator>admin</dc:creator>
            <link>http://www.cubrid.org/coding_conventions</link>
            <guid isPermaLink="true">http://www.cubrid.org/coding_conventions</guid>
                                    <description><![CDATA[<h1>CUBRID Coding Conventions</h1>

<h3>Table of Contents</h3>
<ul style="list-style-type: none;">
    <li><a href="#_Toc244441465">1. Introduction</a></li>
    <li><a href="#_Toc244441466">1.1 Need for Coding Convention</a></li>
    <li><a href="#_Toc244441467">1.2 Basic Rules</a></li>
    <li><a href="#_Toc244441468">1.3 Elements of Coding Conventions</a></li>
    <li><a href="#_Toc244441469">1.3.1 Commenting Rules</a></li>
    <li><a href="#_Toc244441470">1.3.2 Naming Rules</a></li>
    <li><a href="#_Toc244441471">1.3.3 Coding Rules</a></li>
    <li><a href="#_Toc244441472">1.4 Terms of Coding Conventions</a></li>
    <li><a href="#_Toc244441473">1.4.1 Syntax Terms</a></li>
    <li><a href="#_Toc244441474">2. Naming Rules</a></li>
    <li><a href="#_Toc244441475">2.1 Common Naming Rules</a></li>
    <li><a href="#_Toc244441476">2.2 File Names</a></li>
    <li><a href="#_Toc244441477">2.3 Function Names</a></li>
    <li><a href="#_Toc244441478">2.4 Variable and Constant Names</a></li>
    <li><a href="#_Toc244441479">2.5 Type Names</a></li>
    <li><a href="#_Toc244441480">3. Coding Rules</a></li>
    <li><a href="#_Toc244441481">3.1 Indentation</a></li>
    <li><a href="#_Toc244441482">3.2 Others</a></li>
    <li><a href="#_Toc244441483">4. Commenting Rules</a></li>
    <li><a href="#_Toc244441484">4.1 Common Rules</a></li>
    <li><a href="#_Toc244441485">4.2 How to Write Different Formats of Comments</a></li>
    <li><a href="#_Toc244441486">4.3 How to Write Different Usage of Comments</a></li>
    <li><a href="#_Toc244441487">5. Rules for Declarations and Definitions</a></li>
    <li><a href="#_Toc244441488">5.1 Function Declaration and Writing</a></li>
    <li><a href="#_Toc244441489">5.2 Variable Declarations</a></li>
    <li><a href="#_Toc244441490">5.3 Common Type Declaration</a></li>
    <li><a href="#_Toc244441491">5.4 Constant Declarations</a></li>
    <li><a href="#_Toc244441492">6. Rules for Expressions and Statements</a></li>
    <li><a href="#_Toc244441493">7. File Configuration and Information</a></li>
    <li><a href="#_Toc244441494">7.1 Program Configuration</a></li>
    <li><a href="#_Toc244441495">7.2 File Configuration</a></li>
    <li><a href="#_Toc244441496">7.3 Header Files</a></li>
    <li><a href="#_Toc244441497">7.4 Source Files</a></li>
    <li><a href="#_Toc244441498">8. Compatibility</a></li>
    <li><a href="#_Toc244441499">9. Security</a></li>
    <li><a href="#_Toc244441500">9.1 Assertion</a></li>
    <li><a href="#_Toc244441501">10. Other Rules</a></li>
</ul>

<h2><a name="_Toc244441465"></a>1. Introduction</h2>
<p>This chapter describes the need for CUBRID coding conventions, and elements and terms of coding conventions.</p>
<h3><a name="_Toc186633614"></a><a name="_Toc186632731"></a><a name="_Toc186632417"></a><a name="_Toc186631881"></a><a name="_Toc186631368"></a><a name="_Toc186631264"></a><a name="_Toc244441466"></a>1.1 Need for Coding Convention</h3>
<p>A large amount of maintenance cost is required throughout the software lifecycle. In addition, it is unlikely that the original developer of source code continues to maintain it for the whole lifecycle. Therefore, writing the source code in a way a person other than the original developer can understand it quickly and accurately is essential in reducing source code maintenance cost and increasing job efficiency.</p>
<p>With its high readability, source code written according to coding conventions helps developers to understand it quickly and accurately. This also makes easier to share them among project members and possible to produce a consistent source code appearance.</p>
<h3><a name="_Toc244441467"></a>1.2 Basic Rules</h3>
<p>Basically, CUBRID adopts “GNU Coding Standards” and “C Style and Coding Standards for SunOS” as its coding guide. It only uses basic features of the C/C++ language (compiler); it is not recommended to use techniques that are not used commonly.</p>
<p><b>GNU Coding Standards</b><br /><a href="http://www.gnu.org/prep/standards/standards.pdf">http://www.gnu.org/prep/standards/standards.pdf</a></p>

<p><b>SunOS Coding Standards</b><br /><a href="http://opensolaris.org/os/community/on/cstyle.ms.pdf">http://opensolaris.org/os/community/on/cstyle.ms.pdf</a></p>
<p>This document describes a part to emphasize or additionally defined rules in the above guide.</p>
<h3><a name="_Toc244441468"></a>1.3 Elements of Coding Conventions</h3>
<h4><a name="_Toc244441469"></a>1.3.1 Commenting Rules</h4>
<p><b>Implementation Comment </b></p>
<p>Implementation comments describe implementation details or additional explanations, not source code specifications.</p>
<p><b>Documentation Comment</b></p>
<p>Documentation comments describe source code specifications. Developers can understand source codes through documentation comments.</p>

<h4><a name="_Toc244441470"></a>1.3.2 Naming Rules</h4>
<p>Naming rules are used to write names of functions and variables. These names should be descriptive enough to easily tell developers the source code structure.</p>
<h4><a name="_Toc244441471"></a>1.3.3 Coding Rules</h4>
<p><b>Indentation</b></p>
<p>Indentation is used to improve the readability of statements; programmers indent a certain amount of spaces from the first column on the left to the column on the right. It shows inclusion relationships between statements and blocks so that developers can easily understand the source code structure</p>
<p><b>Brace </b></p>
<p>Braces are used to indicate declarations and blocks. They show inclusion relationships between declarations, blocks and body.</p>
<p><b>White Space</b></p>
<p>White spaces are used to improve the readability of the source code. Using unnecessary braces or not using them where they are needed decreases the readability.</p>
<h3><a name="_Toc244441472"></a>1.4 Terms of Coding Conventions</h3>
<h4><a name="_Toc244441473"></a>1.4.1 Syntax Terms</h4>
<p><b>Variables </b></p>
<p>A variable is a space in memory where the state of an object or data is stored. It is defined by ANSI as follows:</p>
<p>“A character or a set of characters that represents a value for writing a program. It corresponds to an address in computer programming.”</p>
<p><b>Operators </b></p>
<p>An operator is a special symbol which is used to execute operations.</p>
<p><b>Expressions </b></p>
<p>An expression is an arithmetic or logical expression that returns a single value by using variables, operators and function calls.</p>
<p><b>Statements</b></p>
<p>A statement is a unit of execution, which is represented as an expression or a control flow statement.</p>
<p><b>Blocks </b></p>
<p>A block is an area between a pair of braces. Usually a block contains one or more statements, but it may not contain any in some cases.</p>
<p><b>Control Flow Statements  </b></p>
<p>A control flow statement is a statement that controls the program flow.</p>
<p><b>Declarations  </b></p>
<p>A declaration is used to define names and types of variables/functions, and return values, arguments and bodies of functions.</p>

<h2><a name="_Toc244441474"></a>2.Naming Rules</h2>
<p>This chapter describes naming rules.</p>
<h3><a name="_Toc244441475"></a>2.1 Common Naming Rules
</h3><h4>A. Using lowercase characters</h4>
<p>There are some exceptions, but use lowercase characters for naming.</p>
<h4>B. Avoiding the use of single-character names</h4>
<p>Single-character names are unable to represent their meaning clearly, thus increase the possibility of errors because it is difficult to remember them. However, single-character names can be used as variable names in iterative statements; it is not recommended to use them if you can define a specific meaning.</p>
<h4>C. Using underscores ("_")</h4>
<p>Use underscores (“_”) to separate words.</p>
<h4>D. Choosing words</h4>
<p>The choice of words should be consistent as much as possible. For similar words such as add/insert, store/save/put, remove/delete, for example, use one of them consistently.</p>
<h4>E. Avoiding use of abbreviations</h4>
<p>For file, function, variable and constant names, use full names, not abbreviations. For example, use print_value or initialize_parameters instead of prt_val or init_params. However, commonly-known abbreviations and the ones frequently used as local variable names are allowed.</p>
<p>[Table 2-1] Example of Using Abbreviations</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Item</b></p>
            </td>
            <td width="448" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Example</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Bad example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">prt_val, init_params</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Good example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">print_value, initialize_parameters</p>
            </td>
        </tr>
    </tbody>
</table>
<p>[Table 2-2] Example of Available Abbreviations</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.95pt;">
            <td width="576" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 432.2pt; height: 14.95pt;">
            <p style="margin-left: 0in;" class="n"><b>Available Abbreviations</b></p>
            </td>
        </tr>
        <tr style="height: 14.95pt;">
            <td width="576" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 432.2pt; height: 14.95pt;">
            <p style="margin-left: 0in;" class="n">min, max</p>
            </td>
        </tr>
    </tbody>
</table>
<h4>F. Avoiding the use of negative Boolean names</h4>
<p>Negative Boolean names represent double negative, making difficult to be understood. Therefore, use positive Boolean names.</p>
<p>[Table 2-3] Example of Using Boolean Names</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Item</b></p>
            </td>
            <td width="448" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Example</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Bad example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">is_not_available</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Good example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">is_available</p>
            </td>
        </tr>
    </tbody>
</table>
<h4>G. Observing simplicity and clarity</h4>
<p>Use simple and clear names for files, functions, variables and constants so that they can represent their roles and purposes. It is recommended to use nouns with adjectives.</p>
<h4>H. Observing English Word Order</h4>
<p>Observe English word order when you create a name by combining multiple words. The following word order is recommended.</p>
<p></p><ul><li>Verb + Object.</li><li>Subject + Verb + Object</li><li>Subject + Verb</li><li>djective + Noun</li></ul><p></p>



<p>More accurate conventions are described in the detailed naming rules for functions and variables.</p>
<p>[Table 2-4] Example of English Word Order</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Item</b></p>
            </td>
            <td width="448" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Example</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Bad example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">date_check</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Good example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">check_date</p>
            </td>
        </tr>
    </tbody>
</table>

<h3><a name="_Toc244441476"></a>2.2 File Names</h3>
<h4>A. Using descriptive file names</h4>
<p>Use descriptive file names that note the contents of the file.</p>
<h4>B. Avoiding the use of duplicate file names</h4>
<p>Do not use duplicate file names in the same project.</p>
<h4>C. Avoiding the use of special characters</h4>
<p>Do not use special characters other than underscores ("_").</p>
<h4>D. Using lowercase alphabets</h4>
<p>Use lowercase alphabets to create file names; use underscores ("_") between words.</p>
<h4>E. Using prefixes</h4>
<p>Use sub-system names as prefixes to create file names systematically. However, a prefix is not used for the name of a file which constitutes a common module.</p>
<p>[Table 2-5] Example of File Names</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Item</b></p>
            </td>
            <td width="448" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Example</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Example of using a prefix</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">connection_list_sr.c</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Example of a common module</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">tcp.c</p>
            </td>
        </tr>
    </tbody>
</table>
<h4>F. Using unique names</h4>
<p>Do not use name that are likely to be duplicated; use unique names.</p>
<p>[Table 2-6] Example of Unique Names</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Item</b></p>
            </td>
            <td width="448" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Example</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Bad example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">evaluator.c</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="117" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 88pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Good example</p>
            </td>
            <td width="448" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 335.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">query_evaluator.c</p>
            </td>
        </tr>
    </tbody>
</table>
<h4>G. File Extension Rules</h4>
<p>Comply with the rules described in Chapter 2 of SunOS Guide.</p>
<p>[Table 2-7] File Extension Rules</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>File</b></p>
            </td>
            <td width="374" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Extension</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">C source file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.c</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Assembly source file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.s</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Object file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.o</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Header file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.h</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Archive library file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.a</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">C shell source file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.csh</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Bourne shell source file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.sh</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">ANTLR<span style="font-family: Arial;">  grammar file</span></p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.g</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Yacc source file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.y</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="191" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 143.2pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Lex source file</p>
            </td>
            <td width="374" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 280.7pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">.l</p>
            </td>
        </tr>
    </tbody>
</table>
<h3><a name="_Toc244441477"></a><a name="_??_??"></a>2.3 Function Names</h3>
<p>Use prefix_verb_noun(_suffix) format for a function name. For a prefix, use an abbreviation that represents a corresponding module.</p>
<p>For a function name, use a verb to say what a function does. Start a function name with the "get_" prefix if the function is a get that reads data. Start a function name with the "set_" prefix if the function is a set that sets data. Use a verb such as "is_" or "has_" for a function that returns a Boolean type.</p>
<p>[Table 2-7] Example of Function Names</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="172" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 129pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Item</b></p>
            </td>
            <td width="393" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 294.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Example</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="172" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 129pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">Example</p>
            </td>
            <td width="393" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 294.9pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">qdump_print_xasl_type</p>
            </td>
        </tr>
    </tbody>
</table>
<h3><a name="_Toc244441478"></a>2.4 Variable and Constant Names</h3>
<p>Names of variables and constants have prefix_noun(_suffix) format; adjective or adverb can be used. A compound noun such as noun+noun+noun format can be also used. For a prefix, a module name is used.</p>
<h4>A. Global Variable Names</h4>
<p>Use an uppercase character only for the first one after a prefix. For example, prm_Parameter_definition. This also applies to static global variables.</p>
<h4><a name="_??_??__Local"></a>B. Local Variable Names</h4>
<p>Do not use a prefix and use a simple name. More abbreviations are allowed for local variable names. However, if there are more appropriate ones than a, b, c or i, j, k, use them. For example, use a self-explanatory name that delivers meaning such as first_param. For a pointer variable, use "_p" as a suffix.</p>
<h4>C. Constant Names</h4>
<p>Use uppercase characters such as PRM_QUERY_CACHE_OPTION for a constant name.</p>
<h4>D. Macro Names</h4>
<p>As a constant-like global variable, use uppercase characters for a macro name that is defined with #define. However, when defining a constant, it is recommended to use a variable that include "const" rather than using a macro definition.</p>
<h3><a name="_Toc244441479"></a>2.5 Type Names</h3>
<h4>A. Type, Struct and Enum Names</h4>
<p>Use only lowercase characters for type, struct and enum names; only uppercase characters for typedef names. Do not use a suffix such as _t for a type name.</p>
<p>[Table 2-8]Example of Type, Struct, Enum and Typedef Names</p>
<table cellspacing="0" cellpadding="0" border="1" style="border: medium none ; border-collapse: collapse;" class="MsoNormalTable">
    <tbody>
        <tr style="height: 14.05pt;">
            <td width="106" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 79.4pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Item</b></p>
            </td>
            <td width="459" valign="top" style="border-style: solid none; border-color: windowtext -moz-use-text-color rgb(38, 38, 38); border-width: 1.5pt medium 1pt; padding: 0in 1.4pt; width: 344.5pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><b>Example</b></p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="106" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 79.4pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">typedef</p>
            </td>
            <td width="459" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 344.5pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">typedef SCAN_CODE</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="106" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 79.4pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">struct</p>
            </td>
            <td width="459" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color rgb(38, 38, 38); border-width: medium medium 1pt; padding: 0in 1.4pt; width: 344.5pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">struct log_2pc_coordinator</p>
            </td>
        </tr>
        <tr style="height: 14.05pt;">
            <td width="106" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 79.4pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n">enum</p>
            </td>
            <td width="459" valign="top" style="border-style: none none solid; border-color: -moz-use-text-color -moz-use-text-color windowtext; border-width: medium medium 1.5pt; padding: 0in 1.4pt; width: 344.5pt; height: 14.05pt;">
            <p style="margin-left: 0in;" class="n"><span style="color: rgb(102, 102, 102);">enum log_flush</span></p>
            </td>
        </tr>
    </tbody>
</table>
<h4>B. Struct Member Name</h4>
<p>Use only lowercase characters; do not use a prefix.</p>
<h4><a name="_??_????_?"></a>C. Function Parameter Names</h4>
<p>Create a function parameter name in the same way as described in <a href="#_??_??_(Local">Local Variables</a>.</p>
<p>This chapter describes coding rules..</p>
<h2><a name="_Toc244441480"></a>3.Coding Rules</h2>
<h3><a name="_Toc244441481"></a>3.1 Indentation</h3>
<h4>A. Observing tab spacing</h4>
<p>Use GNU indent without an option. Note that the indent program does not perfectly process #if/#else/#endif of cpp.</p>
<p></p><ul><li>For indent tool manuals, see the following web site: <a href="http://www.gnu.org/software/indent/manual">http://www.gnu.org/software/indent/manual</a></li></ul><p></p>

<div class="code"><div class="code_header">[Code 3-1] Example of Indentation</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
static bool qdump_print_db_value_array (DB_VALUE ** array_p, int count)
{
	int i;

	if (array_p == NULL)
	{
		return true;
	}
 
	for (i = 0; i &lt; count; i++, array_p++)
    {
		if (!qdump_print_db_value (*array_p))
        {
			return false;
        }
		
		fprintf (foutput, "; ");
    }
 
	return true;
}
</div>
</div>

<h4>B. Observing indentation of enum definition</h4>
<p>When you define an enumeration type value, write each item on a new line with indentatio.</p>

<div class="code"><div class="code_header">[Code 3-2] Example of Indentation of enum Definition</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
typedef enum
{
	LC_OBJECT = 0,              /* Don't know if it is an instance or a class */
	LC_CLASS,                   /* A class  */
	LC_INSTANCE                 /* An instance  */
} LC_OBJTYPE;
</div>
</div>

<h4>C. Observing indentation of function parameters</h4>
<p>When you define a function, if it cannot be defined in a single line because there are too many input parameters, move the last parameter in the line to the next line. Set the indentation of parameters in the next line to the column where the first parameter begins.</p>

<div class="code"><div class="code_header">[Code 3-3] Example of Indentation of Function Definition Parameters</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
static void rop_to_range (RANGE * range, ROP_TYPE left, ROP_TYPE right);
static void range_to_rop (ROP_TYPE * left, ROP_TYPE * rightk, RANGE range);
static ROP_TYPE compare_val_op (DB_VALUE * val1, ROP_TYPE op1,
DB_VALUE * val2, ROP_TYPE op2);
</div>
</div>

<h4>D. Observing indentation of function use parameters</h4>
<p>When you define a function, if it cannot be defined in a single line because there are too many input parameters, move the last parameter in the line to the next line. Set the indentation of parameters in the next line to the column where the first parameter begins.</p>

<div class="code"><div class="code_header">[Code 3-4] Example of Indentation of Function Use Parameters</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/* check if the two key ranges are mergable */
if (compare_val_op (&amp;curp-&gt;key2, cur_op2,
	&amp;nextp-&gt;key1, next_op1) == ROP_LT ||
	compare_val_op (&amp;curp-&gt;key1, cur_op1,
	&amp;nextp-&gt;key2, next_op2) == ROP_GT)
    {
		/* they are disjoint */
		nextp++;
		next_n++;
		continue;
	}
</div>
</div>

<h4>E. Observing indentation of logical expressions</h4>
<p>If a condition statement consisting of multiple logical operators, and they cannot be written in a single line, break up the logical expression into multiple lines. Place one logical operator per line, or combine multiple operators based on logical operation order.</p>
<p>If the line break is based on logical operators, indent a line by a tab from the column where the first logical expression started, beginning from the second line.</p>

<div class="code"><div class="code_header">[Code 3-5] Example of Indentation of Logical Expressions</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
if ((s_id-&gt;direction == S_FORWARD &amp;&amp; s_id-&gt;position == S_BEFORE)
    || (!BTREE_END_OF_SCAN (&amp;s_id-&gt;s.isid.bt_scan)
    || s_id-&gt;s.isid.indx_info-&gt;range_type == R_KEYLIST
    || s_id-&gt;s.isid.indx_info-&gt;range_type == R_RANGELIST))
</div>
</div>

<h3><a name="_Toc244441482"></a>3.2 Others</h3>
<h4>A. Adding blanks</h4>
<p>Place a space between words, before and after an operator, and after punctuation marks (e.g. comma, colon, etc.). However, spacing may not be required when unary operators are used. In addition, the last line should not be blank.</p>
<h4>B. Using spaces for blanks</h4>
<p>Except for a tab that is created by indentation, use a space for a blank instead of a tab.</p>
<h4>C. Priority</h4>
<p>When you write an expression, use parentheses to clearly specify the order of operations if multiple operators are used.</p>

<div class="code"><div class="code_header">[Code 3-6] Example of Priority</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
a = k * ((b + c) / d);
</div>
</div>

<h4>D. Number of columns</h4>
<p>Write source code within 80 columns. If a comment is long, arrange it appropriately (see the Comments section).</p>
<h4>E. Blocks</h4>
<p>A brace and a control statement must be written on separate lines.</p>

<div class="code"><div class="code_header">[Code 3-7] Example of Blocks</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
switch (last_scan_p-&gt;position)
{
	case S_BEFORE:
		status = qfile_scan_list_next (thread_p, next_scan_p, next_tuple_p, PEEK);
		break;

	case S_ON:
		do
		{
			status = qfile_scan_list_next (thread_p, next_scan_p, next_tuple_p, PEEK);
			
			if (status != S_SUCCESS)
			{
				break;
			}

			error_code = qfile_compare_tuple_helper (last_tuple_p-&gt;tpl,
												next_tuple_p-&gt;tpl,
												types, &amp;cmp);
		}
		
		while (error_code == NO_ERROR &amp;&amp; cmp == 0);
		break;

	case S_AFTER:
	default:
		status = S_END;
		break;
}
</div>
</div>

<h2><a name="_Toc244441483"></a>4. Commenting Rules</h2>
<p>&nbsp;</p>
<p>This chapter describes commenting rules.</p>
<p>&nbsp;</p>
<h3><a name="_Toc244441484"></a>4.1 Common Rules</h3>
<p>Comments are used to improve understanding of source code by providing brief explanation or describing additional information that cannot be delivered just with the code.</p>
<h4>A. Basic rules</h4>
<p></p><ul><li>All comments must be written in English.</li><li>Simple comments: Complicated comments are difficult to read and to modify, increasing the possibility that improper comments are left as they are. Therefore, write simple comments only with necessary contents.</li></ul><p></p>

<h4>B. Source code that does not need comments</h4>
<p>?Comments are not needed if you can clearly understand only by reading source code.</p>
<p>?Do not write comments about packaging or build. (e.g. directory information to be located)</p>
<p>?Do not write comments about source code developers or revision history. To provide this information, use a logging feature of the configuration management system.</p>
<p>There are three formats of comments: block comments, single-line comments and trailing comments. In terms of usage, there are file comments, function comments, variable comments, etc.</p>
<h3><a name="_Toc244441485"></a>4.2 How to Write Different Formats of Comments</h3>
<h4>A. Block Comments</h4>
<p>This format is used when comments are written in multiple lines. There are two types as shown below.</p>
<div class="code"><div class="code_header">[Code 4-1] Example of Comments at the Top of the Code</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/*
* This comment lines are too long to write within one line.
* So, you can choose proper style like this. It is up to you.
* GNU indent will not violate this style of comment.
*/
</div>
</div>

<div class="code"><div class="code_header">[Code 4-2] Comments within the Code</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/* Nonzero means truncate lines in the display;
zero means continue them. */
</div>
</div>

<p>This format with * in every line is used to write comments at the top of the code, such as file comments and function comments.</p>
<p>For comments within the code, start with /*, do not use * when a line changes and end with */ according to the GNU definition. In addition, use the same indentation as the code.</p>
<h4>B. Single-line comments</h4>
<p>For a single-line comment, write comments in the following format.</p>

<div class="code"><div class="code_header">[Code 4-3] Example of Single-Line Comments</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/* codes to be used in the module */
</div>
</div>

<h4>C. Trailing Comments</h4>
<p>This format is used to add a short comment beside the code.</p>

<div class="code"><div class="code_header">[Code 4-4] Example of Trailing Comments</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
int trail_file_vdes = 0;      /* the trail log file descriptor */
</div>
</div>

<h3><a name="_Toc244441486"></a>4.3 How to Write Different Usage of Comments</h3>
<p>Write comments at the top of the code for declaration and definition (e.g. function, variable and type); write comments at the end of the code for struct members or local variables. Make sure that comments at the end of the code do not go over the next line.</p>
<h4>A. File comments</h4>
<p>File comments are written in the following format. The copyright statement is followed by the GPL license statement.</p>
<p>

</p><div class="code"><div class="code_header">[Code 4-5] Example of File Comments</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/*
 * Copyright (C) 2008 Search Solution Corporation. All rights reserved by Search Solution.
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */
 
/*
 * list_file.c - Query List File Manager
 */
 
#ident "$Id$"
</div>
</div>

<h4><a name="_??_??"></a>B. Function comments</h4>
<p>Function comments are written in the block comment format. The first line describes brief information about a function, and the second line describes a value that the function returns. The third line and the rest lines describe the parameters of the function. Specify in, out, or on/out for each parameter. After the parameter description, add brief information that can help improve understanding of the function.</p>

<div class="code"><div class="code_header">[Code 4-6] Example of Function Comments</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/*
 * qfile_copy_list_id - Copy contents of source list_id into destionation list_id
 *  return: NO_ERROR or ER_FAILED
 *  dest_list_id(out): destination list_id
 *  src_list_id(in): source list_id
 *  include_sort_list(in):
 */
int
qfile_copy_list_id (QFILE_LIST_ID * dest_list_id_p,
                   const QFILE_LIST_ID * src_list_id_p,
                   bool is_include_sort_list)
</div>
</div>

<h4><a name="_??_??"></a>C. Variable comments</h4>
<p>Comments are written for static variable declaration in the following format (see the GNU coding guide).</p>

<div class="code"><div class="code_header">[Code 4-7] Example of Variable Comments</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/* Nonsero means truncate lines in the display;
zero means continue them. */
int truncate_lines;
</div>
</div>

<h4>D. Type/struct comments</h4>
<p>Comments with the format /* … */ are also used for struct, enum and typedef. In addition, write comments for a condition after #else and #endif (see the GNU Standard).</p>

<div class="code"><div class="code_header">[Code 4-8] Example of #ifdef Comments</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
#ifdef foo
…
#else /* not foo */
…
#endif /* not foo */
#ifdef foo
#endif /* foo */
 
#ifndef foo
…
#else /* foo */
..
#endif /* foo */
 
#ifndef foo
…
#endif /* foo */
</div>
</div>

<h2><a name="_Toc244441487"></a>5. Rules for Declarations and Definitions</h2>
<p>&nbsp;</p>
<p>This chapter describes functions/variable declarations, common type definitions, initialization and using macros.</p>
<p>&nbsp;</p>
<h3><a name="_Toc244441488"></a>5.1 Function Declaration and Writing</h3>
<p>For the naming rules of functions and parameters, see Chapter 2. Naming Rules; for the commenting rules, see Chapter 4. Commenting Rules.</p>
<p></p><ul><li>Function naming rules: <a href="#_??_??">2.3 Function Names</a></li><li>Function parameter naming rules: <a href="#_??_????_?">2.5 C Function parameters</a></li><li>Function commenting rules: <a href="#_??_??">4.3 B Function comments</a></li></ul><p></p>


<h4>A. Observing simplicity and clarity</h4>
<p>Write simple and clear functions. Long functions decrease readability and make maintenance difficult. It is recommended that the length of a function do not exceed 200 lines.</p>
<h4>B. Observing the one-task-per-function rule</h4>
<p>Implement a function so that it performs only one task. A function performing multiple tasks is difficult to understand because it decreases simplicity and clarity. Non-intuitive functions are likely to generate errors. Therefore, implement a function that performs a single task.</p>
<h4>C. Function declaration rules</h4>
<p>Do not use old declarations such as INTERFACE, PUBLIC, or PRIVATE; instead, only static and extern should be used. In addition, function declarations must be included in a header file (.h) and source file (.c). Even for a static function, function declaration must be included at the beginning of a source file. Use an appropriate header file in a source file instead of declaring an external function with extern rather than #include.</p>
<h4>D. Validating input parameters</h4>
<p>Write code that checks the validity of input parameters passed into the function.</p>
<h4>E. Parameter declaration rules</h4>
<p>Basically, declare function parameters in the order of out, in/out, and in. However, parameters that are frequently used throughout a module and passed like the keyword "this" of C++ (e.g. PT_PARSER parser, etc.) must be located at the beginning. For input parameters, use the const specifier. And use a pointer every place where const is required, such as const char * const in_p.</p>
<h4>F. Function return value rules</h4>
<p>Basically, create a function that can return an error code. If it is more significant to return a pointer value as void *malloc() or char *strcpy(), create a function that accepts an error code as an output parameter. That is, every function must return an error code in general. Only when a function is clear, it can return 0 or NULL. For example, int (*compar)(const void *, const void *) in qsort() returns a specific value instead of an error code.</p>
<p>Error codes are negative numbers, but NO_ERROR is 0 exceptionally. Basically, an error code means ER_XXXX_XXXX (a global error code) defined in dber.h. If it is necessary to define its own code in a module or function due to a program structure, define the code by using enum in a header file. In this case, use a negative number for an error. If it is not an error, use 0. That is, make the following statement become TRUE in most cases.</p>

<div class="code"><div class="code_header">[Code 5-1] Example of Error Processing</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
if (xx_function() &lt; 0)
if (xx_function() != NO_ERROR)
</div>
</div>

<p>Although an error code is defined as DB_ERROR type, typedef is not used to define it in the code. (NO_ERROR is defined as 0.) Therefore, most functions have int as a return type. If the result of a function is positive number, it is a result of the function. If it is a negative number, it is one of error codes defined in DB_ERROR. If there is a function whose return type is DB_BOOL in the code, change its return type to int and make it return an appropriate error code.</p>
<p>When a function is called, perform an error checking for the result value. Even when the called function always return the same value, you must check the result value if the function is designed to return an error code according to its definition. In addition, checking result values must be performed after calling system functions. Especially, an error checking must be performed for malloc(). And make sure that exceptions are handled appropriately.</p>
<h3><a name="_Toc244441489"></a>5.2 Variable Declarations</h3>
<p>For the naming rules of variables, see Chapter 2. Naming Rules; for the commenting rules, see Chapter 4. Commenting Rules.</p>
<p></p><ul><li>Variable naming rules: <a href="#_??_?_??">2.4 Variable and Constant Names</a></li><li>Variable commenting rules: <a href="#_??_??">4.3 C Variable comments</a></li></ul><p></p>

<h3><a name="_Toc244441490"></a>5.3 Common Type Declaration</h3>
<p>If you want to use typedef for struct/enum, declare typedef first. If names are not specified in struct/enum, process them at once as follows:</p>

<div class="code"><div class="code_header">[Code 5-2] Example of Defining Common Types without Specifying Names</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
typedef enum
{
    FALSE = 0,
    TRUE = 0
} bool;
</div>
</div>

<h3><a name="_Toc244441491"></a>5.4 Constant Declarations</h3>
<p>Place a constant defined by #define within a block by using parentheses if the constant contains an expression. By doing so, you can prevent operation priority issues. However, #define is replaced during compilation and the name is not displayed in the symbol table, making debugging difficult. Therefore, use enum and const instead of #define when you declare a constant. The first element of enum must be set to 0.</p>

<div class="code"><div class="code_header">[Code 5-3] Bad Example of Processing Constants</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
#define MAX_SPEED 256
</div>
</div>

<div class="code"><div class="code_header">[Code 5-4] Good Example of Processing Constants</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
typedef enum
{
	LC_OBJECT = 0,              /* Don't know if it is an instance or a class */
	LC_CLASS,                   /* A class  */
	LC_INSTANCE                 /* An instance  */
} LC_OBJTYPE;
</div>
</div>

<h2><a name="_Toc244441492"></a>6. Rules for Expressions and Statements</h2>
<p>This chapter describes rules for writing expressions and statements.</p>
<p>These rules correspond to the SunOS Guide (see Chapter 9, Chapter 15, and Chapter 17).</p>
<p></p><ul><li>Chapter 9: Statements</li><li>Chapter 15: Goto</li><li>Chapter 17: Multiple Assignments</li></ul><p></p>


<p>This chapter describes how to write file configuration and information.</p>
<h2><a name="_Toc244441493"></a>7. File Configuration and Information</h2>
<h3><a name="_Toc244441494"></a>7.1 Program Configuration</h3>
<p>These rules correspond to the SunOS Guide.</p>
<p></p><ul><li>Chapter 3  Program Organization</li></ul><p></p>
<h3><a name="_Toc244441495"></a>7.2 File Configuration</h3>
<p>These rules correspond to the SunOS Guide.</p>
<p></p><ul><li>Chapter 4: File Organization</li></ul><p></p>
<h3><a name="_Toc244441496"></a>7.3 Header Files</h3>
<p>The structure of the header file (.h) is described below.</p>
<p>1. Copyright statement</p>
<p>2. Comments that describe the file contents, if necessary</p>
<p>3. Include checking with #ifndef</p>
<p>4. #ident line</p>
<p>5. #include other header files (system header first)</p>
<p>6. Repeat the followings in meaningful units</p>
<p></p><ul><li>#define, etc.</li><li>typedef definition</li><li>strcut, enum definition</li><li>extern global variable declaration</li><li>extern function declaration</li></ul><p></p>

<div class="code"><div class="code_header">[Code 7-1] Example of Header File</div>
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/*
 * Copyright (C) 2008 Search Solution Corporation.
* All rights reserved by Search Solution.
 *
 * This program is free software;
* you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street,Fifth Floor,Boston,MA 02110-1301 USA
 *
 */
 
/*
 * hdr.h - Brief description of this file as one sentence
 *
 * Note: if you feel the need
 */
 
#ifndef _HDR_H_
#define _HDR_H_
 
#ident "$Id$"
 
/* Explain main concept or logic of your code
   contained in this file if possible */
 
#include "other.h"
 
#define DEFINE define
 
typedef strcut record RECORD;
 
/* codes to be used in the module */
enum code { CODE1, CODE2, CODE3 };
/* … */
struct record {
  int no;
size_t size;
};
 
/* … */
extern int hdr_Global_variable;
 
/* … */
extern int hdr_process_line(char *line, int line_no);
extern int hrd_end_of_processing(const char *line);
 
#endif _HDR_H_
</div>
</div>

<h3><a name="_Toc244441497"></a>7.4 Source Files</h3>
<p>The structure of the source file (.c) is described below.</p>
<p>1. Copyright statement</p>
<p>2. #ident line</p>
<p>3. Comments that describes the file contents, if necessary</p>
<p>4. #include header file (system header first)</p>
<p>5. You can write the followings in meaning units.</p>
<p></p><ul><li>#define, etc.</li><li>typedef definition</li><li>strcut, enum definition</li><li>static variables definition</li><li>static function declaration</li><li>function definition (execution code)</li></ul><p></p>

<p>Here, it is not recommended to place struct far way from a related typedef; declarations must be grouped in the same place. In addition, if there is #define that is only used for a specific function, it can be used at the beginning of the function or within the function.</p>
<p>The following formats used in the old file structure should not be used.</p>

<div class="code">
<div class="code" editor_component="code_highlighter" code_type="bash" file_path="" description="" first_line="1" collapse="true" nogutter="false" nocontrols="false">
/***** IMPORTED DECLARATIONS*****/

/***** PUBLIC DEFINES *****/

/***** PUBLIC TYPEDEFS*****/

/****** PRIVATE DECLARATIONS *****/
</div>
</div>

<h2><a name="_Toc244441498"></a>8.Compatibility</h2>
<p>This chapter describes how to implement compatibility.</p>
<h4>A. Using compatibility related types</h4>
<p>Do not use int instead of size_t or off_t that is available in the C library. If necessary, use int32_t or uint32_t. The recommended basic types are defined in the config.h. The types defined in dbport.h (e.g. DB_INT32 or DB_BOOL) must be used mostly for API.</p>
<h4>B. Others</h4>
<p>The additional information regarding compatibility corresponds to the SunOS Guide.</p>

<ul><li>Chapter 20: Portability</li></ul>

<h2><a name="_Toc244441499"></a>9. Security</h2>
<p>This chapter describes how to implement security code.</p>
<h3><a name="_Toc244441500"></a>9.1 Assertion</h3>
<p>Use assert() appropriately in the code after #include assert.h. Do not use it frequently and try to avoid calling other functions in the assert expression. The most recommended types are as follows:</p>

<ul><li>Checking whether a parameter of a function is valid</li><li>Warning risks in advance</li><li>Verifying a return value at the end of a function as a unit test</li></ul>


<h2><a name="_Toc244441501"></a>10. Other Rules</h2>
<p>This chapter describes other rules to comply with.</p>

<ul><li>Delete the extern "C" part.</li><li>Do not use inline or register.</li><li>Use volatile only for very sensitive parts.</li><li>After coding, use the GNU indent to align the indentation.</li><li>There must be no warning by compiling with the following option in the gcc:<br /><b>-all -extra -missing-prototypes -redundant-decls -long-long</b></li><li>Check the code by using splint if the compiling is successful.</li></ul>]]></description>
                        <pubDate>Fri, 09 Apr 2010 12:15:21 -0800</pubDate>
                                </item>
            </channel>
</rss>
