0

Possible Duplicate:
Why cast an unused value to void?

for this C++ code:

MyClass::myFunc(int val)
{
//some code
(void)val;
//somecode
}

why may we need to cast val to void without being assigned to another variable ?

Community
  • 1
  • 1
Ahmed Adel
  • 329
  • 4
  • 10

1 Answers1

1

This is done to shut up the compiler, warning about an unused variable.

Tony The Lion
  • 57,181
  • 57
  • 223
  • 390
  • 1
    Good stuff, but wouldn't it be better to close duplicates and redirect to the canonical question rather than producing additional, duplicate answers? – Kerrek SB Sep 16 '12 at 13:45
  • Thanks Tony, really this variable was never used through out the rest of the code .. – Ahmed Adel Sep 16 '12 at 14:02