[comp.lang.c++] Can I turn off specific "not used" warnings in cfront?

herrage@ntpal.UUCP (Robert Herrage) (11/13/90)

I'm sending this a different way since the first way hasn't been
working very well.  So, if you're getting this again, I apologize.

Yes! You can eliminate the "not used" warnings!  Below is a simple
example:

void funcname(
  int x;
  int y;
  int z      )
{
  x,y; // this will eliminate the "not used" warnings

  printf( "%d", z );

}

reb@starwolf.Solbourne.COM (Roy Binz) (11/14/90)

> Yes! You can eliminate the "not used" warnings!  Below is a simple
> example:
> 
> void funcname(
>   int x;
>   int y;
>   int z      )
> {
>   x,y; // this will eliminate the "not used" warnings
> 
>   printf( "%d", z );
> 
> }

Actually, it is even easier than that! Using your example:

	void funcname(
	  int /* x */,		// This may look strange, but it works
	  int /* y */,		// and it is intended to be this way!
	  int z      )
	{
	  printf( "%d", z );
	}

You can also completely omit the parameter names, but my experience has been
that leaving them in helps other people who have to read the code.

	Roy Binz
--
	Roy Binz
	Solbourne Computer Inc.		Domain: reb@Solbourne.COM
	1900 Pike Rd.			UUCP: ...!{boulder,sun}!stan!reb
	Longmont, Colorado 80501	Phone : 303-678-4307

tom@elan.Elan.COM (Thomas Smith) (11/15/90)

From article <1084@ntpal.UUCP>, by herrage@ntpal.UUCP (Robert Herrage):
> 
> 
> I'm sending this a different way since the first way hasn't been
> working very well.  So, if you're getting this again, I apologize.
> 
> Yes! You can eliminate the "not used" warnings!  Below is a simple
> example:
> 
> void funcname(
>   int x;
>   int y;
>   int z      )
> {
>   x,y; // this will eliminate the "not used" warnings
> 
>   printf( "%d", z );
> 
> }

However, this could (on some compilers) generate code for the
comma-separated expression "x,y;".  There are two other alternatives:

1) If the variable that you don't want to use is a function parameter,
   as in the example above, simply leave off the parameter name from the
   definition.  i.e.
	void funcname(int, int, int z)  { printf("%d", z); }

2) If the variable is an automatic variable or a global (such as SCCS ids)
   I found that if you define an inline function that takes a parameter,
   but has no body, no code will be generated.  i.e.
      inline void NotUsed(const void *anything) {}

      NotUsed(SCCSid);		// suppresses "not used" warning

Hope this helps,
    Thomas Smith
    Elan Computer Group, Inc.
    (415) 964-2200
    tom@elan.com, ...!{ames, uunet, hplabs}!elan!tom

mat@mole-end.UUCP (Mark A Terribile) (11/15/90)

> Yes! You can eliminate the "not used" warnings!  Below is a simple
> example:
 
> void funcname(
>   int x;
>   int y;
>   int z )
> {
>   x,y; // this will eliminate the "not used" warnings
> 
>   printf( "%d", z );
> 
> }

Yes, it will eliminate the warnings, but it won't compile.  I think you
mean

	void funcname(
	  int x,
	  int y,
	  int z )
	{
	  x,y; // this will eliminate the "not used" warnings

	  printf( "%d", z );

	}

but it's the wrong way to do it.  (It's also a bear of a way to format
code.)

The right way is to use the language as it is meant to be used:

	void
	funcname( int, int, int z )
	{
		cout << z;
	}

(Note that we also get rid of the incompletely type-checked  printf() .)
What if you need the `documentation' value of the  x  and  y ?  You can
always place a prototype in front of the function:

	void funcname( int x, int y, int z );

	void
	funcname( int, int, int z )
	{
			. . .
-- 

 (This man's opinions are his own.)
 From mole-end				Mark Terribile

jbate@mentor.com (John Bate) (11/17/90)

In article <878@elan.Elan.COM> tom@elan.Elan.COM (Thomas Smith) writes:
>From article <1084@ntpal.UUCP>, by herrage@ntpal.UUCP (Robert Herrage):
>> 
>> 
>> I'm sending this a different way since the first way hasn't been
>> working very well.  So, if you're getting this again, I apologize.
>> 
>> Yes! You can eliminate the "not used" warnings!  Below is a simple
>> example:
>> 
>> void funcname(
>>   int x;
>>   int y;
>>   int z      )
>> {
>>   x,y; // this will eliminate the "not used" warnings
>> 
>>   printf( "%d", z );
>> 
>> }

Here is another way:


void funcname(
   const char *a,
   long i,
   char *b
)
{
   (const void *) a;
   (void) i;
   (void *) b;

   // do something here
}

Hope this helps.


-- 
John Bate, Mentor Graphics Corporation,
8500 S.W. Creekside Pl., Beaverton, OR, 97005-7191, (503) 626-7000

aw1r+@andrew.cmu.edu (Alfred Benjamin Woodard) (11/19/90)

elliott@veronica.cs.wisc.edu (James Elliott) writes:

> ... I get tons of warnings about unused variables.
> Normally these are very handy, but this time I >know< I am not using
> them, and can't really do anything about it. This makes it difficult
> for me (and Emacs) to sift actual errors out of the sea of warnings.
> 
This might sound like a silly solution but I solved the same type of
problem a while back. I was working under unix using csh and so I
simply piped all my compile output through grep:
EX:
	CC foo.c |& fgrep warning

I had to use |& rather than | because I compile errors come through
stderr rather than stdout.

Hope this helps.

-ben

richard@dataspan.dataspan.UUCP (Richard "Tiger" Melville) (11/20/90)

In article <1084@ntpal.UUCP> herrage@ntpal.UUCP (Robert Herrage) writes:

>   Yes! You can eliminate the "not used" warnings!  Below is a simple
>   example:

>   void funcname(
>     int x;
>     int y;
>     int z      )
>   {
>     x,y; // this will eliminate the "not used" warnings
>
>     printf( "%d", z );
>   }

I do this:

   void funcname(int, int, int z) {
     printf( "%d", z );
   }








--
             _Q     Q_       Richard Melville DataSpan Technology Inc.  
      __    /_\)   /|        237-9313         400-540 5th ave SW
_\___/O____O|/O____/ \_                       Calgary Alberta Canada, T2P 0M2
 _/  \_