warn.h
header#include "/package/prog/prjlibs/include/warn.h" { WARN_CHK(1>=1u); WARN_TYPE(char*, "foo"); WARN_PTYPE(char**, "foo"); WARN_CAST(char*, "foo"); WARN_ARR(char, "foo"); WARN_IF(1==0); if (NOWARN_SIGNED(uid_t)) { ... } if (NOWARN_UNSIGNED(uid_t)) { ... } if (NOWARN_NEGATIVE(uid_t, uid)) { ... } }
The warn.h
C header file provides macros to provoke or inhibit
compiler warnings.
WARN_CHK(expr)
is a void expression
which avoids evaluating the given expression at run time, but still
allows it to be visible to the compiler to provoke warnings.
WARN_TYPE(type, expr)
is a void
expression triggering a warning if the given expression is not
assignment-compatible with the given type. It is mostly useful in the
definitions of other macros, when you want to perform type checking as
functions do. The given expression is not evaluated at run time. The
type must be specified in a form that can have "*
"
appended to it to form the associated pointer type - in particular,
pointer-to-function and pointer-to-array types must be specified through
typedefs.
WARN_PTYPE(ptype, expr)
is a void
expression triggering a warning if the given expression is not
assignment-compatible with the dereferenced form of the given type. It
is useful for pointer-to-function and pointer-to-array types, where
WARN_TYPE
cannot be used.
WARN_CAST(type, expr)
evaluates to
the given expression, cast to the given type, but triggering a warning if
the expression is not assignment compatible with that type. The type
specification has the same restrictions as with
WARN_TYPE
.
WARN_ARR(type, expr)
is a void
expression triggering a warning if the given expression is not an array
whose base type is the given type. It is mostly useful in the
definitions of other macros, when you want to perform type checking as
functions do. The given expression is not evaluated at run time.
WARN_IF(expr)
is a void expression
triggering a warning if the given expression evaluates to nonzero. The
expression should be an integer constant expression; it is not evaluated
at run time.
NOWARN_SIGNED(type)
returns
nonzero iff the given integer type is signed, without triggering a
warning.
NOWARN_UNSIGNED(type)
returns nonzero iff the given integer type is unsigned, without
triggering a warning.
NOWARN_NEGATIVE(type, expr)
returns nonzero iff the given expression, when cast to the given type,
yields a negative value, without triggering a warning. The expression
may be evaluated more than once.