Function to do nothing

M

Michael

Hi,
all is going fine, but I'm compiling with max warnings, and I get a lot of
warnings to tell me that some parameter passed is not being used. Is there a
way of telling the compiler that its ok? eg pointers i can do:
if( pIn) ;
then i don't get the complaint (something else instead ;-) )but I could do
with something like:

void func(int i1,int i2, int i3)
{
#pragma NOTUSED (i1,i2)

printf("%d",i3)
}

Sorry if its compiler specific.

Mike
 
D

Dave Vandervies

Hi,
all is going fine, but I'm compiling with max warnings, and I get a lot of
warnings to tell me that some parameter passed is not being used. Is there a
way of telling the compiler that its ok? eg pointers i can do:
if( pIn) ;
then i don't get the complaint (something else instead ;-) )but I could do
with something like:

void func(int i1,int i2, int i3)
{
#pragma NOTUSED (i1,i2)

printf("%d",i3)
}

Isn't this what unnamed parameters are for?

void func(int,int,int i3)
{
printf("%d",i3);
}


dave
 
A

Andrew Koenig

all is going fine, but I'm compiling with max warnings, and I get a lot
of
warnings to tell me that some parameter passed is not being used. Is there
a
way of telling the compiler that its ok? eg pointers i can do:
if( pIn) ;
then i don't get the complaint (something else instead ;-) )but I could do
with something like:

void func(int i1,int i2, int i3)
{
#pragma NOTUSED (i1,i2)

printf("%d",i3)
}

It depends on your compiler, of course, but as a general notion it would
seem that if you aren't using a parameter, you shouldn't be giving it a
name:

void func(int, int, int i3)
{
// etc.
}
 
M

Maxim

Michael wrote :
Hi,
all is going fine, but I'm compiling with max warnings, and I get a lot of
warnings to tell me that some parameter passed is not being used. Is there a
way of telling the compiler that its ok? eg pointers i can do:
if( pIn) ;
then i don't get the complaint (something else instead ;-) )but I could do
with something like:

void func(int i1,int i2, int i3)
{
#pragma NOTUSED (i1,i2)

printf("%d",i3)
}


#define NOTUSED(_V) ((void) (_V))

void func(int i1,int i2, int i3)
{
NOTUSED(i1);
NOTUSED(i2);
printf("%d",i3)
}


(follow up to comp.lang.c)
 
D

Dave Vandervies

Maxim said:
#define NOTUSED(_V) ((void) (_V))

void func(int i1,int i2, int i3)
{
NOTUSED(i1);
NOTUSED(i2);
printf("%d",i3)
}


(follow up to comp.lang.c)

Wouldn't it make more sense to give a C++ answer and leave the thread
in clc++?

If the OP wanted a C answer, he'd've posted in comp.lang.c in the first
place, no?

And even assuming that he really wanted a C answer, your solution isn't
valid, since it uses an identifier reserved for the implementation
(see n869 7.1.3).


dave
 
D

DaKoadMunky

It depends on your compiler, of course, but as a general notion it would
seem that if you aren't using a parameter, you shouldn't be giving it a
name:

If a parameter is unnamed, and presumably therefore unusable, can the compiler
eliminate the passing of the argument to the function?
 
D

David Lindauer

DaKoadMunky said:
If a parameter is unnamed, and presumably therefore unusable, can the compiler
eliminate the passing of the argument to the function?

probably not since the prototype can have unnamed parameters in either case...

David
 
H

Howard

Michael said:
Hi,
all is going fine, but I'm compiling with max warnings, and I get a lot
of
warnings to tell me that some parameter passed is not being used. Is there
a
way of telling the compiler that its ok? eg pointers i can do:
if( pIn) ;
then i don't get the complaint (something else instead ;-) )but I could do
with something like:

void func(int i1,int i2, int i3)
{
#pragma NOTUSED (i1,i2)

printf("%d",i3)
}

Sorry if its compiler specific.

Mike

Just an FYI: besides using unnamed parameters, you can also do this:

void func( int i1, int i2, int i3 )
{
i1;
i2;
printf("%d",i3);
}


-Howard
 
O

Old Wolf

If the OP wanted a C answer, he'd've posted in comp.lang.c in the first
place, no?

This answer works in both C and C++ (in C you cannot have unnamed
parameters).

(For some definitions of "works", one compiler I use will still
issue the warning for this form of NOTUSED).
And even assuming that he really wanted a C answer, your solution isn't
valid, since it uses an identifier reserved for the implementation
(see n869 7.1.3).

I don't think preprocessor tokens are identifiers. In the
preprocessed output, _V will not appear. If there is already
a _V defined, then it will be superseded by the new _V for the
scope of the macro definition.

For example I could go:
#include <stdio.h>
#define BAR(NULL)
BAR(a)
just fine.
 

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
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top