What's the meaning of (void) cast?

A

alex

The following function is quoted from Judy source code:

//
****************************************************************************
// J U D Y F R E E

void JudyFree(
void * PWord,
Word_t Words)
{
(void) Words;
free(PWord);

} // JudyFree()


Obviously, this is a wrapper routine to free memory. However, what's
the purpose of (void)Words ?
Also, learned from the calling codes, I think the second parameter is
the size of memory pointed by the first parameter.

Thanks
 
I

Ian Collins

alex said:
The following function is quoted from Judy source code:

//
****************************************************************************
// J U D Y F R E E

void JudyFree(
void * PWord,
Word_t Words)
{
(void) Words;
free(PWord);

} // JudyFree()


Obviously, this is a wrapper routine to free memory. However, what's
the purpose of (void)Words ?

It's probably there to suppress unused parameter warnings from some
compilers.
 
J

J. J. Farrell

alex said:
The following function is quoted from Judy source code:

//
****************************************************************************
// J U D Y F R E E

void JudyFree(
void * PWord,
Word_t Words)
{
(void) Words;
free(PWord);

} // JudyFree()


Obviously, this is a wrapper routine to free memory. However, what's
the purpose of (void)Words ?
Also, learned from the calling codes, I think the second parameter is
the size of memory pointed by the first parameter.

It does nothing, but does it explicitly. It's a bit like the big fat lie
"this page intentionally left blank" which you sometimes see in formal
documents.

It is most likely being used as a way to stop a compiler issuing a
warning about 'Words' not being referenced in the function. Most
compilers will issue such warnings if their warning level is turned up
high enough, and there are various tricks to tell the compiler "yes, I
know, don't bother telling me about it". The appropriate trick varies
with the compiler, as some will issue other warnings about some of the
tricks.

Another similar tick you may come across is

Words = Words;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top