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

founded 2 years ago
MODERATORS
 

I've always found C++'s "trend" of handling normal or non-exceptional system errors with exceptions lackluster (and I'm being charitable). Overall trimming things down to (basically) passing around a couple integers and telling the user to check their manual is much better, much less error prone, and much more efficient and deterministic.

you are viewing a single comment's thread
view the rest of the comments
[–] SpaceNoodle@lemmy.world 4 points 3 weeks ago (1 children)

-Wunused-result is good practice in general

[–] benni@lemmy.world 2 points 3 weeks ago (1 children)

I'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.

[–] SpaceNoodle@lemmy.world 3 points 3 weeks ago (2 children)

Right, so just cast the returned value to void: (void)function();

[–] mercator_rejection@programming.dev 3 points 3 weeks ago (2 children)

The new C++ way is

std::ignore = function();
[–] SpaceNoodle@lemmy.world 1 points 3 weeks ago* (last edited 3 weeks ago)

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.

[–] lambalicious@lemmy.sdf.org 0 points 3 weeks ago

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 stds and colons. (void) is a classic and works everywhere.

But hey, at least it's not static_cast<void>(...).

[–] benni@lemmy.world 2 points 3 weeks ago

Cool, I didn't know that was a thing 👍