This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Suppressing gcc warnings
- To: <gcc-help at gcc dot gnu dot org>
- Subject: Suppressing gcc warnings
- From: "Rimmer, Todd" <trimmer at infiniconsys dot com>
- Date: Wed, 22 Aug 2001 19:12:47 -0400
> Hello,
> I am presently using the gcc 2.72 and 2.95.2 compilers to
> generate code for an embedded application. As part of this effort I
> attempting to make the code warning clean. However I have run into a
> number of warnings which I have been unable to properly suppress
> (short of disabling warnings all together, which I would like to
> avoid).
>
> Is there a way in gcc to suppress the following warnings. I would
> especially like to suppress them for the specific lines of code which
> have been verified to be correct. I have made use of
> __attribute__((unused)) successfully, but have not found a similar
> documented way to suppress the warnings below.
>
> warning: comparison is always true due to limited range of data type
> example use:
> template<class Type>
> bool IsPowerOf2(Type value)
> {
> ASSERT(value >= 0);
> // algorithm to determine if value is a power of 2
> }
> In the above example, the Type could be int, unsigned, etc. Hence the
> ASSERT is useful. However when Type is unsigned, the warning is
> generated.
>
> warning: cast from pointer to integer of different size
> occurs due to casts from pointer to int as part of a logging
> subsystem.
> It happens varargs in not available due to underlying
> implementation
> in the embedded OS. I would like to suppress for the line of
> code involved (which happens to be in a macro)
>
> warning: `class X' only defines a private destructor and has no
> friends
> example use: a class with reference counting
> class X
> {
> public:
> X();
> int AddRef();
> int Release();
> private:
> ~X();
> }
> Singletons (with static methods to Create object and a private
> constructor/destructor) generate similar messages.
>
> warning: unused parameter 'int x'
> __attribute__((unused)) does not seem to work in the context of
> the parameter list to a function, causes syntax error in 2.95.2
> compiler
> Also tried __unused__. These do however work for variable
> declaration.
> int SomeFunc(int arg1 __attribute__((unused)), int arg2)
> causes syntax errors. While:
> int SomeFunc(int arg1, int arg2)
> {
> int somevar __attribute__((unused)) = 5;
> // more code
> }
> works.
> I also tried the old /* ARGSUSED */ lint comment preceeding the
> function to no avail.
>
> Todd Rimmer
> Staff Software Engineer InfiniCon Systems
> Voice: 610-205-0130x19 Fax: 610-205-0488
> TRimmer@InfiniConSys.com www.InfiniConSys.com
>