2

In my current program I have a function already defined as

void functionName( const customClass object );

Now, in the code for this function, this object is not used. I don't have permission to to remove the parameter, nor can I remove the unused parameter warning.

Is there a statement I can execute with this object (customClass doesn't have any functions which I can run here), so that this warning doesn't happen?

Parag Gupta
  • 117
  • 1
  • 8

4 Answers4

7

You can remove the name of the parameter from the definition:

void functionName( const customClass );

This doesn't change the signature of the function (it's compatible with your existing declaration), but since the variable isn't named there won't be an unused parameter warning.

DRH
  • 7,868
  • 35
  • 42
  • @Ringding and @DRH: That didn't work. I get a new error `error: '' has incomplete type` – Parag Gupta Dec 21 '11 at 06:49
  • @Parag: Strange. What DRH posted is a common C++/C99 solution. While I have posted another, "old" C compatible solution, this should work. Can you perhaps post a more complete code showing the error? – Suma Dec 21 '11 at 06:53
  • 1
    An incomplete type error usually implies that the declaration of the class is not visible in this translation unit. Even if you aren't using the class, you'll still need to make sure it is defined in the translation unit. A more complete example (declaration of customClass, declaration of functionName, definition of functionName) might help in diagnosing this error. – DRH Dec 21 '11 at 06:56
4

You can remove the name of the argument, "object".

Ringding
  • 2,856
  • 17
  • 10
4

Common way to do this is

void functionName(const customClass object)
{
    (void)object; // gets rid of warning
}
Suma
  • 33,181
  • 16
  • 123
  • 191
1
void functionName(const customClass object)
{
    object; // gets rid of warning
}

I think you can cast it to void, too ie: (void)object;, but I'm not entirely sure. Macros such as UNREFERENCED_PARAMETER do this.

#define UNREFERENCED_PARAMETER(P) (P)
void functionName(const customClass object)
{
    UNREFERENCED_PARAMETER(object);
}
Marlon
  • 19,924
  • 12
  • 70
  • 101
  • 1
    I'm sorry. This doesn't work. The (void)Object; does though. This creates a new warning regarding a no-effect statement. – Parag Gupta Dec 21 '11 at 06:55