logoalt Hacker News

Am4TIfIsER0pposlast Sunday at 10:26 PM2 repliesview on HN

You've defined that function with an attribute saying not to ignore the returned value. Is it right to explicitly silence an explicit warning?


Replies

amlutolast Monday at 1:47 AM

I want some defined way to tell the compiler that I am intentionally ignoring the result.

I encounter this when trying to do best-effort logging in a failure path. I call some function to log and error and maybe it fails. If it does, what, exactly, am I going to do about it? Log harder?

show 1 reply
MathMonkeyManlast Sunday at 10:42 PM

Sometimes. For example, you might be setting a non-crucial option on a socket, and if it fails you don't even care to log the fact (maybe the logging would be too expensive), so you just ignore the return value of whatever library is wrapping setsockopt.