Skip to content
Snippets Groups Projects
Commit 3f7bf074 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Define and use a new IGNORE_RESULT() macro

Historically, casting to void would suppress warnings about things
being unused.  However, an attribute was created for functions like
realloc() where not using the result is always a bug, so when the
attribute is used, you must actually use the return value and can't
cast to void to avoid a warning.

Given this attribute, the glibc authors decided to apply it to all
the functions that usually should have their return value checked
(chdir(), write(), etc) when _FORTIFY_SOURCE is defined because if
you care about correctness enough to define _FORTIFY_SOURCE, you'll
always do something useful with these return values.

Extending the hilarity, some distros define _FORTIFY_SOURCE by
default.

The result is functions that occasionally can safely be called
regardless of the return value will throw a warning if you don't
"do something" with that return value.

Of course, you can just turn off the warnings completely with a
compiler flag, but then you lose the excellent warning about things
like realloc() that always make sense and were the original reason
for the option.
parent 0f04d3ac
Branches
Tags
No related merge requests found
Pipeline #7610 passed
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment