The check can also be controlled by passing the command-line option
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:
Part of the TenDRA Web.8.2 Enumerations controlling switch statements
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:
#pragma TenDRA enum switch analysis status
where status is on
(raise an error),
warning
(produce a warning), or off
(the
default mode when no errors are produced).8.3 Incomplete structures and unions
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:
struct tag *p;
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:
#pragma TenDRA complete struct/union analysis status
where status
is on
to give an error as an
incomplete structure or union is detected, warning
to
give a warning, or off
to disable the check.-X:complete_struct=
state
to tchk, where
state
is check
, warn
or dont
.
struct tag *p;
struct tag {
int a;
int b;
};
struct tag is complete despite the fact that it was incomplete in
the definition of p.8.4 Variable shadowing
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 "shadowed" 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:
#pragma TenDRA variable hiding analysis status
If status is on
an error is raised when a local
variable that shadows another variable is declared, if
warning
is used the error is replaced by a warning and
the off
option restores the default behaviour (shadowing
is permitted and no errors are produced).8.5 Floating point equality
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:
#pragma TenDRA floating equality permit
where
permit
is
allow
, warning
or disallow
. By default
the check is switched off.
Crown
Copyright © 1998.