Connecting Tech Pros Worldwide Forums | Help | Site Map

Function to do nothing

Michael
Guest
 
Posts: n/a
#1: Jul 22 '05
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



Andrew Koenig
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Function to do nothing


"Michael" <slick_mick_00@hotmail.com> wrote in message
news:cnbmpk$c77$1@sparta.btinternet.com...
[color=blue]
> 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)
> }[/color]

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.
}


Dave Vandervies
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Function to do nothing


In article <cnbmpk$c77$1@sparta.btinternet.com>,
Michael <slick_mick_00@hotmail.com> wrote:[color=blue]
>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)
>}[/color]

Isn't this what unnamed parameters are for?

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


dave

--
Dave Vandervies dj3vande@csclub.uwaterloo.ca
Perhaps the original version of the program worked.
OK, this takes us *way* off topic for any computer related newsgroup, but
you've got to admit its a theoretical possibility. --Ken Hagan in comp.arch
Maxim
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Function to do nothing


Michael wrote :[color=blue]
> 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)
> }[/color]


#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)

--
Maxim
"Amour de putain feu d'estoupe."
- proverbe françois

Dave Vandervies
Guest
 
Posts: n/a
#5: Jul 22 '05

re: Function to do nothing


In article <mn.80c77d4b3dc842e6.20219@bboy>,
Maxim <box4spam+newsgroups@gmail.com> wrote:
[color=blue]
>#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)[/color]

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

--
Dave Vandervies dj3vande@csclub.uwaterloo.ca
Perhaps the original version of the program worked.
OK, this takes us *way* off topic for any computer related newsgroup, but
you've got to admit its a theoretical possibility. --Ken Hagan in comp.arch
DaKoadMunky
Guest
 
Posts: n/a
#6: Jul 22 '05

re: Function to do nothing


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

If a parameter is unnamed, and presumably therefore unusable, can the compiler
eliminate the passing of the argument to the function?
David Lindauer
Guest
 
Posts: n/a
#7: Jul 22 '05

re: Function to do nothing




DaKoadMunky wrote:
[color=blue][color=green]
> >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:[/color]
>
> If a parameter is unnamed, and presumably therefore unusable, can the compiler
> eliminate the passing of the argument to the function?[/color]

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

David
Michael
Guest
 
Posts: n/a
#8: Jul 22 '05

re: Function to do nothing


Thanks guys, that was exactly what i was after.
Mike

"David Lindauer" <camille@bluegrass.net> wrote in message
news:4199788D.ED65438@bluegrass.net...[color=blue]
>
>
> DaKoadMunky wrote:
>[color=green][color=darkred]
> > >It depends on your compiler, of course, but as a general notion it[/color][/color][/color]
would[color=blue][color=green][color=darkred]
> > >seem that if you aren't using a parameter, you shouldn't be giving it a
> > >name:[/color]
> >
> > If a parameter is unnamed, and presumably therefore unusable, can the[/color][/color]
compiler[color=blue][color=green]
> > eliminate the passing of the argument to the function?[/color]
>
> probably not since the prototype can have unnamed parameters in either[/color]
case...[color=blue]
>
> David[/color]


Howard
Guest
 
Posts: n/a
#9: Jul 22 '05

re: Function to do nothing



"Michael" <slick_mick_00@hotmail.com> wrote in message
news:cnbmpk$c77$1@sparta.btinternet.com...[color=blue]
> 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
>
>[/color]

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



Old Wolf
Guest
 
Posts: n/a
#10: Jul 22 '05

re: Function to do nothing


dj3vande@csclub.uwaterloo.ca (Dave Vandervies) wrote:[color=blue]
>[color=green]
> >#define NOTUSED(_V) ((void) (_V))
> >
> >void func(int i1,int i2, int i3)
> >{
> > NOTUSED(i1);
> > NOTUSED(i2);
> > printf("%d",i3)
> >}[/color][/color]
[color=blue]
> If the OP wanted a C answer, he'd've posted in comp.lang.c in the first
> place, no?[/color]

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).
[color=blue]
> 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).[/color]

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.
Closed Thread