version 1.1, 2013/01/21 13:43:51
|
version 1.3, 2013/02/18 15:00:19
|
|
|
<em>Approved version (Ballot 160).</em> | <em>Approved version (Ballot 160).</em> |
</td> | </td> |
</tr> | </tr> |
|
<tr> |
|
<td align="center">3.4</td> |
|
<td align="center">22 January 2013</td> |
|
<td align="center">Marek Szermutzky</td> |
|
<td>Adding section on Unused's (variables, |
|
arguments, values etc.)</td> |
|
</tr> |
|
<tr> |
|
<td align="center">3.5</td> |
|
<td align="center">22 January 2013</td> |
|
<td align="center">Marek Szermutzky</td> |
|
<td>macro PEGASUS_FCT_EXECUTE_AND_ASSERT added</td> |
|
</tr> |
</table> | </table> |
<p> </p> | <p> </p> |
<hr> | <hr> |
|
|
declarations and definitions.</li> | declarations and definitions.</li> |
</ol> | </ol> |
| |
|
<h3>Avoiding Unused parameter, variables, values, functions ...</h3> |
|
<p>In general, avoid unused variables, parameters, values and |
|
functions. Many compiler come with support to automatically detect |
|
these, use them. The OpenPegasus build using gcc will flag unused variables |
|
as errors. |
|
The Pegasus Architecture team may completely disallow checkin of code that |
|
generates unused* warnings to CVS in the future.<br> |
|
</p> |
|
<ol> |
|
<li>Avoid unused parameter warnings. In case the function |
|
signature cannot be changed since the function codes an |
|
interface, leave the parameter name off in the function |
|
definition while keeping the parameter type in place. In the |
|
following example of function <i>main()</i> the parameter <i>argv</i> |
|
is used later on but parameter <i>argc</i> is not. Do this:<br> |
|
<pre><code>int main(int, void** argv) |
|
{ |
|
};</code></pre> |
|
Not this:<br> |
|
<pre><code>int main(int argc, void** argv) |
|
{ |
|
};</code></pre> |
|
</li> |
|
<li>Avoid unused variables when the return value of a function is |
|
assigned to a variable only to be used to do an assert check |
|
with PEGASUS_ASSERT by instead using macro |
|
PEGASUS_FCT_EXECUTE_AND_ASSERT. It helps avoid such unused |
|
variables when PEGASUS_NOASSERTS is enabled (assertion |
|
disabled). PEGASUS_FCT_EXECUTE_AND_ASSERT compares the return |
|
value of function against VALUE for equalness but only if |
|
asserts are enabled. The Function FCT will always be called |
|
(equal if asserts enabled or disabled). Do this: |
|
<pre><code>PEGASUS_FCT_EXECUTE_AND_ASSERT(true, f()); |
|
</code></pre> |
|
Not this: |
|
<pre><code>bool returnCode = f();<br>PEGASUS_ASSERT(true == returnCode); |
|
</code></pre> |
|
</li> |
|
|
|
</ol> |
|
|
| |
<h2><font color="#000000">Discussion</font></h2> | <h2><font color="#000000">Discussion</font></h2> |
<p>Suggestions for additional conventions are listed here for discussion: | <p>Suggestions for additional conventions are listed here for discussion: |