Subversion Repositories tendra.SVN

Rev

Rev 2 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<!-- Crown Copyright (c) 1998 -->
<HTML>
<HEAD>
<TITLE>C Checker Reference Manual: Common Errors</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#400080" ALINK="#FF0000">
<A NAME=S108>
<H1>C Checker Reference Manual</H1>
<H3>January 1998</H3>
<A HREF="tdfc12.html"><IMG SRC="../images/next.gif" ALT="next section"></A>
<A HREF="tdfc10.html"><IMG SRC="../images/prev.gif" ALT="previous section"></A>
<A HREF="tdfc1.html"><IMG SRC="../images/top.gif" ALT="current document"></A>
<A HREF="../index.html"><IMG SRC="../images/home.gif" ALT="TenDRA home page">
</A>
<IMG SRC="../images/no_index.gif" ALT="document index"><P>
<HR>
<DL>
<DT><A HREF="#S109"><B>8.1 </B> - Introduction</A><DD>
<DT><A HREF="#S110"><B>8.2 </B> - Enumerations controlling switch
statements</A><DD>
<DT><A HREF="#S111"><B>8.3 </B> - Incomplete structures and unions</A><DD>
<DT><A HREF="#S112"><B>8.4 </B> - Variable shadowing</A><DD>
<DT><A HREF="#S113"><B>8.5 </B> - Floating point equality</A><DD>
</DL>

<HR>
<H1>8  Common Errors</H1>
<A NAME=S109>
<HR><H2>8.1  Introduction</H2>
Tchk is capable of performing a number of checks for common programming
mistakes. This chapter describes these checks and controlling pragmas.<P>
<A NAME=S110>
<HR><H2>8.2  <A NAME=2>Enumerations controlling switch statements</H2>
Enumerations are commonly used as control expressions in switch statements.
When case labels for some of the enumeration constant belonging to
the enumeration type do not exist and there is no default label, the
switch statement has no effect for certain possible values of the
control expression. Checks to detect such switch statements are controlled
by:<P>
<PRE>
        #pragma TenDRA enum switch analysis <EM>status</EM>
</PRE>
where <EM>status</EM> is <CODE>on</CODE> (raise an error), 
<CODE>warning</CODE> (produce a warning), or <CODE>off</CODE> (the
default mode when no errors are produced).<P>
<A NAME=S111>
<HR><H2>8.3  <A NAME=4>Incomplete structures and unions</H2>
ISO C allows for structures or unions to be declared but not defined,
provided they are not used in a context where it is necessary to know
the complete structure. For example:<P>
<PRE>
        struct tag *p;
</PRE>
is allowed, despite the fact that struct tag is incomplete. The TenDRA
C checker has an option to detect such incomplete structures or unions,
controlled by:<P>
<PRE>
        #pragma TenDRA complete struct/union analysis <EM>status</EM>
</PRE>
where <CODE>status</CODE> is <CODE>on</CODE> to give an error as an
incomplete structure or union is detected, <CODE>warning</CODE> to
give a warning, or <CODE>off</CODE> to disable the check.<P>
The check can also be controlled by passing the command-line option
<CODE>-X:complete_struct=</CODE><CODE>state</CODE> to tchk, where
<CODE>state</CODE> is <CODE>check</CODE>, <CODE>warn</CODE> or <CODE>dont</CODE>.
<P>
The only place where the checker can actually detect that a structure
or union is incomplete is at the end of the source file. This is because
it is possible to complete a structure after it has been used. For
example, in:<P>
<PRE>
        struct tag *p;
        struct tag {
                int a;
                int b;
        };
</PRE>
struct tag is complete despite the fact that it was incomplete in
the definition of p.<P>
<A NAME=S112>
<HR><H2>8.4  <A NAME=6>Variable shadowing</H2>
It is quite legal in C to have a variable in an inner scope, with
the same name as a variable in an outer scope. These variables are
distinct and whilst in the inner scope, the declaration in the outer
scope is not visible - it is &quot;shadowed&quot; by the local variable
of the same name. Confusion can arise if this was not what the programmer
intended. The checker can therefore be configured to detect shadowing
in three cases: a local variable shadowing a global variable; a local
variable shadowing a local variable with a wider scope and a local
variable shadowing a typedef name, by using:<P>
<PRE>
        #pragma TenDRA variable hiding analysis <EM>status</EM>
</PRE>
If <EM>status</EM> is <CODE>on</CODE> an error is raised when a local
variable that shadows another variable is declared, if 
<CODE>warning</CODE> is used the error is replaced by a warning and
the <CODE>off</CODE> option restores the default behaviour (shadowing
is permitted and no errors are produced).<P>
<A NAME=S113>
<HR><H2>8.5  <A NAME=8>Floating point equality</H2>
Due to the rounding errors that occur in the handling of floating
point values, comparison for equality between two floating point values
is a hazardous and unpredictable operation. Tests for equality of
two floating point numbers are controlled by:<P>
<PRE>
        #pragma TenDRA floating equality <EM>permit</EM>
</PRE>
<EM>where</EM><CODE> </CODE><EM>permit</EM><CODE> </CODE><EM>is</EM><CODE>
allow</CODE>, <CODE>warning</CODE> or <CODE>disallow</CODE>. By default
the check is switched off.<P>
<P>
<!-- FM pgf ignored -->
<HR>
<P><I>Part of the <A HREF="../index.html">TenDRA Web</A>.<BR>Crown
Copyright &copy; 1998.</I></P>
</BODY>
</HTML>