Connecting Tech Pros Worldwide Help | Site Map

Function to do nothing

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 22nd, 2005, 09:55 PM
Michael
Guest
 
Posts: n/a
Default Function to do nothing

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



  #2  
Old July 22nd, 2005, 09:55 PM
Andrew Koenig
Guest
 
Posts: n/a
Default 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.
}


  #3  
Old July 22nd, 2005, 09:55 PM
Dave Vandervies
Guest
 
Posts: n/a
Default 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
  #4  
Old July 22nd, 2005, 09:55 PM
Maxim
Guest
 
Posts: n/a
Default 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

  #5  
Old July 22nd, 2005, 09:55 PM
Dave Vandervies
Guest
 
Posts: n/a
Default 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
  #6  
Old July 22nd, 2005, 09:55 PM
DaKoadMunky
Guest
 
Posts: n/a
Default 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?
  #7  
Old July 22nd, 2005, 09:55 PM
David Lindauer
Guest
 
Posts: n/a
Default 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
  #8  
Old July 22nd, 2005, 09:56 PM
Michael
Guest
 
Posts: n/a
Default 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]


  #9  
Old July 22nd, 2005, 09:56 PM
Howard
Guest
 
Posts: n/a
Default 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



  #10  
Old July 22nd, 2005, 09:58 PM
Old Wolf
Guest
 
Posts: n/a
Default 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.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

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 220,840 network members.