Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Should I cast to (void) when I do not use the return value
Parent
Should I cast to (void) when I do not use the return value
I saw at least one compiler (Codewarrior for HC12) warn me if I use a function without using it's return value.
Other compilers (clang/gcc) do not issue a warning though, even when using the std=90
argument.
So should I generally cast the unused return value of a function to (void)
?
Post
I saw at least one compiler (Codewarrior for HC12) warn me if I use a function without using it's return value. [...]
Ye, for that's the right choice.
[...] Other compilers (clang/gcc) do not issue a warning though, even when using the std=90 argument.
It will, provided that the function is correctly marked warn_unused_result
(https://gcc.gnu.org/onlinedocs/gcc-4.6.0/gcc/Warning-Options.html). The software is should be edited as making results use mandatory. Else functions are to return void
.
So should I generally cast the unused return value of a function to (void)?
Never. The returned value is always meaningful and has always to be treated.
0 comment threads