Take the 2-minute tour ×

In C++, void is used to specify a function with no return value. Then there are void pointers, which can be used to point to almost any variable, no matter the type. There is also casting to void, which may come in handy, if you want to suppress warnings of unused function return values.

However, in addition to all those uses mentioned above, there seems to be a use case for void-keyword, which I'm unaware of. This use case exists in the following code (appears in Mesa GL source code):

class count_block_size : public program_resource_visitor {
   count_block_size() : num_active_uniforms(0)
      /* empty */

   unsigned num_active_uniforms;

   virtual void visit_field(const glsl_type *type, const char *name,
                            bool row_major)
      (void) type;
      (void) name;
      (void) row_major;

This use of void near the end of this piece of code perplexes me. What is void in parentheses used for here?

share|improve this question

1 Answer 1

It appears casting to void has been used here to eliminate warnings about unused variables. Some compilers and/or settings provide such warnings. So, casting to void here does none other than silence the compiler about possible warnings.

share|improve this answer

Your Answer


