Function to do nothing 
July 22nd, 2005, 10:55 PM
| | | |
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 | 
July 22nd, 2005, 10:55 PM
| | | | 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.
} | 
July 22nd, 2005, 10:55 PM
| | | | 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 | 
July 22nd, 2005, 10:55 PM
| | | | 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 | 
July 22nd, 2005, 10:55 PM
| | | | 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 | 
July 22nd, 2005, 10:55 PM
| | | | 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? | 
July 22nd, 2005, 10:55 PM
| | | | 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 | 
July 22nd, 2005, 10:56 PM
| | | | 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] | 
July 22nd, 2005, 10:56 PM
| | | | 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 | 
July 22nd, 2005, 10:58 PM
| | | | 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. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,662 network members.
|