Suppressing "Parameter not used" Warning - Page 2

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Re: Suppressing "Parameter not used" Warning
snipped-for-privacy@inspire.net.nz says...
Quoted text here. Click to load it
Metrowerks Codewarrior has the

#pragma unused (varname)

construct to solve this problem.    I'm surprised that other compilers
don't have the same facility.

Mark Borgerson

Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

The trouble with such pragmas is that they are completely non-portable.
  As Grant Edwards said, gcc has an equivalent (using an attribute,
which is gcc prefers over pragmas).  Often non-portability is not a
problem, since there are so many other non-portable aspects to typical
embedded systems (and in the case of gcc, it is at least portable to a
few dozen other gcc ports).

Re: Suppressing "Parameter not used" Warning
snipped-for-privacy@westcontrol.removethisbit.com says...
Quoted text here. Click to load it

I agree that such pragmas are  generally non-portable.  The

Quoted text here. Click to load it

solution seems to be the best seen so far.  I tested it out with
CodeWarrior PalmOS (which I use for some M68K embedded work)  and
it issued no warnings and generated no code.  Can't ask for much
more than that!

In any case,  the fact that you get a warning from the compiler is
a good thing.   I have a lot more problems with porting structures
where I have to worry about packing and endian problems---and where
the compiler hasn't a clue what the code on the other end of the
communications line is doing!

Mark Borgerson


Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

They do (or something similar).

--
Grant Edwards                   grante             Yow!  My mind is making
                                  at               ashtrays in Dayton...
We've slightly trimmed the long signature. Click to see the full one.
Re: Suppressing "Parameter not used" Warning

Quoted text here. Click to load it

I have used a void cast for some compilers.  For another, I was
successful with

#define UNUSED(x)  if(x);

Thad


Re: Suppressing "Parameter not used" Warning
...
Quoted text here. Click to load it

Nice, though some clever compiler could warn here whether or not you're sure
it's what you intend to do, whether or not this code has any effect.

Alex



Re: Suppressing "Parameter not used" Warning
On Tue, 4 Oct 2005 10:37:03 +0400, "Alexei A. Frounze"

Quoted text here. Click to load it

Interesting idea, I'd never thought of that.  Though the lint I use
would surely complain about a "questionable use" of the semicolon
(even if it was removed from the macro itself)  unless you changed it
to something like

   #define UNUSED(x) if(x){}

Regards,

                               -=Dave
--
Change is inevitable, progress is not.

Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

Of course.  The compiler in question (an old Keil compiler) gave a
warning for the void cast.  I experimented and found that if(x);;
(another semicolon added after the macro invocation) generated no code
and no warning for that compiler.  With no standard way to do this, we
are left to search about for implementation-dependent hacks.

Thad


Re: Suppressing "Parameter not used" Warning

[suppressed "parameter not used" warnings]
Quoted text here. Click to load it

Personally, I use an implementation-dependent feature that works
for the compilers I really care about.  Why worry about trying to
suppress warnings on every compiler?  It's not possible and you
could waste a lot of time trying.
--
"Large amounts of money tend to quench any scruples I might be having."
  -- Stephan Wilms

Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

Here in comp.arch.embedded, anybody with too strong an aversion
to implementation-dependent "hacks" is in for a lifetime of
frustration.  There are just too many times when there simply
is no other way to accomplish that which must be accomplished.

Sure, standard and portable is always a good goal, but when
theres a 90+ percent chance the program is never going to be
compiled by a different compiler or run on a different
platform, there's a limit to how much utility should be
sacrificed and much effort should be expended to avoid usign
somethign like gcc's __attribute__(()) extension.

--
Grant Edwards                   grante             Yow!  My LIBRARY CARD
                                  at               expired...
We've slightly trimmed the long signature. Click to see the full one.
Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

Same here.


I don't know.  I'm certainly not advocating such worry.

Quoted text here. Click to load it

True.  I typically only work with a few compilers and spend a little
time to customize such things as eliminating unneeded warnings, which
allows me to more easily find real problems.  Turning off warnings,
ignoring them, or sprinkling non-standard code throughout is a last
resort for me.  You may have other techniques that work better for
you.

Thad

Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

Indeed there is a much better technique.
Make clean code. Catch the warnings in a file.
Carefully inspect the warnings and head them.
Catch the warnings on the resulting cleaner code.
Now in the regression test, expect the warnings to remain
the same, i.e. make a diff with the file with the warnings
of the previous test.
Only act on warnings changes, indicative of new warnings.
Or on warnings that went away since you cleaned up your code.

Never ever becludge your code to suppress warnings.
They are there to ... warn you, which is a Good Thing.

Quoted text here. Click to load it


--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- like all pyramid schemes -- ultimately falters.
We've slightly trimmed the long signature. Click to see the full one.
Re: Suppressing "Parameter not used" Warning

# Indeed there is a much better technique.
# Make clean code. Catch the warnings in a file.

Recompile megabytes of source code because you change one
function declaration in a header file.

--
SM Ryan http://www.rawbw.com/~wyrmwif /
Raining down sulphur is like an endurance trial, man. Genocide is the
We've slightly trimmed the long signature. Click to see the full one.
Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it
[snip]
Quoted text here. Click to load it

This idea has been wandering around me for some time, too.
It could work like this: programmer puts #pramas in the code,
which contain verbatim quotes (or regexes, or identifires) of warnings
that are to be suppressed for the next line.  The utility program (or
a script) calculates line numbers and produces a list of warnings
(with the line numbers) to cut out from the compiler output.
Like this:
  #pragma nowarn t.c:%n: warning: comparison between signed and unsigned
  if (u>s)

--
Stan Tobias
mailx `echo snipped-for-privacy@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`

Re: Suppressing "Parameter not used" Warning


S.Tobias wrote On 10/13/05 17:19,:
Quoted text here. Click to load it

    Ugh.  Ugh ugh ugh.

    First, while the use of warning-suppressing tags in the
code goes back at least to lint, using #pragma to express
them is a truly terrible idea.  Somewhere there'll be a
compiler that actually recognizes "#pragma nowarn" and does
something with it -- for example, suppressing all warning
messages for the entire translation unit, or turning on
ARN (automatic name rewriting) NOW.  Embed such tags in
specially-formatted comments that are linquistically inert,
not in constructs that might at any moment turn into toxic
chemicals and rot your program.

    (Aside: I quite understand that the idea of "a different
compiler" may well be foreign to many projects of interest
in comp.arch.embedded.  However, the thread is cross-posted
to comp.lang.c as well, where portability concerns appear to
carry somewhat more weight.)

    Second, a far better way to suppress the warning you
mention is

    if (u > (unsigned)s)

Sometimes it can be a bad thing for a "last resort" mechanism
to exist: it's too easy for people to give up searching for
the "first resort."

    Finally, and it's been said before: The goal of turning
of ALL warnings from ALL compilers is ultimately futile,
because compilers are allowed to complain about anything
they feel like.  "Warning: Source was modified at 2:37 AM;
sleep-deprived programmer may have made more mistakes than
usaul."

--
snipped-for-privacy@sun.com


Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it
That's how great ideas die - someone says "ugh"...  ;-)

Quoted text here. Click to load it
:-)
Quoted text here. Click to load it
That's true.  All #pragmas (with a small exception) suffer from this
disease.  OTOH the whole concept is subject to implementation behaviour
and is not (universally) portable.  But I agree, it's always better to
avoid a mine-field, and take a quiet and safe path.
(Only, what if the compiler uses the same tags embedded in comments
for its own purposes, too?)

What might actually be bad in practice with #pragmas is that a
compiler might issue warnings about unrecognized #pragmas, thus
we'd be chasing our tail.

Let's make that:
  /* $ nowarn: ... $ */
(Actually, only `$ nowarn: ... $' part is recognized by the utility.)


Quoted text here. Click to load it
That was just a poor example how it could be used.  Anyway,
you had to clutter the code to suppress the warning, too.
Sometimes there's no way of "fixing" warnings for all compilers,
you do it for one, and some other issue arises for another.

Consider this (semi-real-life example):
  off_t  off;
  size_t siz;

  if (siz > off) ;
may cause:
  warning: signed/unsigned in comparison
on one implementation, whereas
  if (siz > (size_t)off) ;
on another may issue:
  warning: possible loss of data in cast
(besides that casting always makes me feel uneasy).
It's not obvious which side to cast to which.

(I actually solved it this way (through a macro):
  if(siz + (off_t)0 > off + (size_t)0) ;
(clue: usual arithmetic conversions).
)

Quoted text here. Click to load it
Well, yes, but my goal is not to turn off ALL warnings, but
only *known* and *inspected* warnings.  The idea is that
I don't waste my work when line numbers change.

--
Stan Tobias
mailx `echo snipped-for-privacy@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`

Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

Lately, I've been fixing this with:

  if (s < 0 || u > (unsigned) s)

but only after careful examination of what s really
represents.  If s just contained a sloppy assignment from
what was previously an unsigned value, then no need for the
extra mathematical rigor.

Also, a lot these warnings arise from people using int when
they should have used size_t.

Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

snip snip

void error_state(uint8_t /* status */)

I prefer to leave the argument there as it should make code easier to
comprehend.  Commenting it out does not need comments.



Re: Suppressing "Parameter not used" Warning
Quoted text here. Click to load it

As noted by an earlier poster, that is not valid for a C function
definition (declaration yes, but not definition which is what was being
discussed).

If you want to discus what you do in C++ (or any language other than C)
then please remove comp.lang.c from the crosspost.
--
Flash Gordon
Living in interesting times.
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline