this post was submitted on 13 Sep 2025
34 points (97.2% liked)
C++
2121 readers
1 users here now
The center for all discussion and news regarding C++.
Rules
- Respect instance rules.
- Don't be a jerk.
- Please keep all posts related to C++.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
-Wunused-result
is good practice in generalI'm mixed on this one, because sometimes you'll want to call a function for its side effects without caring about the return value. E. g. container methods returning an iterator that shows you where the side effect took place.
Right, so just cast the returned value to void:
(void)function();
The new C++ way is
Neat, I learned something. I keep smashing C and C++ together on my head.
The notes on that page do suggest the same method I did, however.
First: it's not new, it's been around since C++03.
Second... it's not even that great. It's more characters to type and you have to deal with
std
s and colons.(void)
is a classic and works everywhere.But hey, at least it's not
static_cast<void>(...)
.Cool, I didn't know that was a thing 👍