Reputation: 439
I am reading source code for a benchmarking utility, In it I see:
int i, j, ret; (void)j; (void)ret;
if (!_does_file_exist(str)) {
sprintf(cmd, "mkdir -p %s > errorlog.txt", str);
ret = system(cmd); // Execute a command on the system
(void)ret;
}
what is the benefit/effect of declaring and casting integers into a void type?
This seems nonsensical.
Upvotes: 0
Views: 185
Reputation: 6748
It's kind of an old-school way of reducing unused variable warnings. I believe it might also force things to be linked in if it is external to the current compilation target. The proper way would be to tag it as unused with whatever way your compiler prefers (and possibly setting that based on autotools or something).
Upvotes: 0
Reputation: 227370
It is quite nonsensical. The (dubious) benefit is to prevent unused variable warnings. Which begs the question, why are the variables declared in the first place?
Upvotes: 3