Reputation: 35984
I have seen the following codes used to call
(void) inotify_rm_watch(fd, wd);
(void) close(fd);
Why not?
inotify_rm_watch(fd, wd);
close(fd);
What is the difference between the two usages?
Upvotes: 0
Views: 199
Reputation: 62553
There are some cases when ignoring return value of the function causes compiler to warn you about it.
Casting return type to void
effectively suppresses the warning. However, the wisdom of ignoring return type is questionable. If function return something, you probably want to know what it returned? Just in case there was a problem, you know.
In particular, inotify_rm_watch
returns -1
when the function fails - and you are usually interested to know it. On the other hand, checking for return value of close
is usually not neccessary and borders with paranoia :)
Upvotes: 6
Reputation: 8563
There is no difference.
The semicolon (;
) effectively means "discard the result you have". Casting to void does nothing in this context.
Upvotes: -3