Compile problem

  • Thread starter Michael L. Hostbaek
  • Start date
M

Michael L. Hostbaek

Hi,

I am trying to compile a piece of software, on a FreeBSD system.

gcc version 2.95.4

When compiling, I get lots of these warnings:

---
logger.c: In function `cf_logger_init':
logger.c:87: warning: unused parameter `argv'
logger.c:87: warning: unused parameter `argc'
logger.c:87: warning: unused parameter `is_compound'
logger.c: In function `logger_output':
logger.c:162: warning: unused parameter `sender'
logger.c: In function `logger_read_pending':
logger.c:177: warning: unused parameter `cc'
logger.c: In function `cf_logger_file':
logger.c:185: warning: unused parameter `argc'
logger.c:185: warning: unused parameter `cmpnd'
logger.c: In function `cf_logger_mode':
logger.c:197: warning: unused parameter `argc'
logger.c:197: warning: unused parameter `cmpnd'
logger.c: In function `cf_logger_trunc':
logger.c:211: warning: unused parameter `argc'
logger.c:211: warning: unused parameter `cmpnd'
---

When I compile on a different FreeBSD system with gcc3.3.1 I am not
getting those warnings.. I'd like to clean up the code, so I can make a
somewhat clean compile.. Is it a known problem ?

TIA,

/mich
 
J

Joona I Palaste

Michael L. Hostbaek said:
Hi,
I am trying to compile a piece of software, on a FreeBSD system.
gcc version 2.95.4
When compiling, I get lots of these warnings:
---
logger.c: In function `cf_logger_init':
logger.c:87: warning: unused parameter `argv'
logger.c:87: warning: unused parameter `argc'
logger.c:87: warning: unused parameter `is_compound'
logger.c: In function `logger_output':
logger.c:162: warning: unused parameter `sender'
logger.c: In function `logger_read_pending':
logger.c:177: warning: unused parameter `cc'
logger.c: In function `cf_logger_file':
logger.c:185: warning: unused parameter `argc'
logger.c:185: warning: unused parameter `cmpnd'
logger.c: In function `cf_logger_mode':
logger.c:197: warning: unused parameter `argc'
logger.c:197: warning: unused parameter `cmpnd'
logger.c: In function `cf_logger_trunc':
logger.c:211: warning: unused parameter `argc'
logger.c:211: warning: unused parameter `cmpnd'

Compilers are free to issue warnings about whatever they want. Here is
an example of a legal compile:

/* test.c */
int main(void) {
return 0;
}

test.c:1: warning: do not play with matches or lighters
test.c:2: warning: do not use electrical equipment when wet
test.c:3: warning: smoking is dangerous to your health

They are even allowed to lie in warnings. The above warnings could just
as easily be:

test.c:1: warning: ISO C forbids use of int main(void)
test.c:2: warning: 0 is not a valid integer
test.c:3: warning: unrecognised token '}'

As long as you get a clean, executable program, the compiler does its
job right.

Now, as the case may be, one compiler you tried likes to issue more
warnings than the other. The ISO C standard does not require compilers
to issue a diagnostic about unused parameters, so compilers are free to
choose whether they want to.

In short, it's a compiler-specific issue. Both compilers are entirely
correct as far as ISO C is concerned.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"The truth is out there, man! Way out there!"
- Professor Ashfield
 
M

Michael L. Hostbaek

Joona I Palaste tried to tell us something, and all I got was:
In short, it's a compiler-specific issue. Both compilers are entirely
correct as far as ISO C is concerned.

I am very well aware of that, however I was wondering if I could change
the code so I would not see all those ugly warnings ;)

/mich
 
J

Joona I Palaste

Michael L. Hostbaek said:
Joona I Palaste tried to tell us something, and all I got was:
I am very well aware of that, however I was wondering if I could change
the code so I would not see all those ugly warnings ;)

The warnings seem to be generated because of unused parameters. To get
rid of these warnings, simply *use* the parameters. For example:

int foo(int bar) {
(void)bar; /* hey look, a use! */
return 0;
}

You could even insert a comment like "Dummy code written just to shut
up gcc".

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery
 
F

Fred L. Kleinschmidt

Joona said:
The warnings seem to be generated because of unused parameters. To get
rid of these warnings, simply *use* the parameters. For example:

int foo(int bar) {
(void)bar; /* hey look, a use! */
return 0;
}

You could even insert a comment like "Dummy code written just to shut
up gcc".

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"I wish someone we knew would die so we could leave them flowers."
- A 6-year-old girl, upon seeing flowers in a cemetery

Many compilers will ignore commenting about unused arguments if the
ARGSUSED comment is placed immediately before the function:

/* ARGSUSED */
void somefunctioin( int notused, ... ) {
/* Body of function, does not reference 'notused'
}
 
E

Ed Morton

<snip>

Here's my entry for the "stating the obvious award": either get rid of
all the parameters the compiler is kindly telling you that you don't use
or add the code where you actually did intend to use them. Once in a
while there may be reasons to have an unused parameter, but they're
often a bug waiting to get hit so make sure you investigate each warning
and decide the code really is OK before adding anything just to get rid
of the warning.

Ed.
 
T

Thomas Stegen

Here's my entry for the "stating the obvious award": either get rid of
all the parameters the compiler is kindly telling you that you don't use
or add the code where you actually did intend to use them. Once in a
while there may be reasons to have an unused parameter, but they're
often a bug waiting to get hit so make sure you investigate each warning
and decide the code really is OK before adding anything just to get rid
of the warning.

Sometimes the prototype of the function is not under your control.
It might be for a callback and for some reason the argument is not
necessary. Sometimes I just assign it to itself. <OT>That might not
be a good idea if C++ is lurking around the corner though.</OT>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,079
Messages
2,570,575
Members
47,207
Latest member
HelenaCani

Latest Threads

Top