Hi folks,
I don't have a real programming issue but more a question on what the difference is; and what is probably the preferable solution.
Assume a function returning a boolean
boolean myReallyDifficultFunction(void);
I have put this into a function, because I need to call this function on different lines in my code. However, I do not need the returned value in any case. So I have basically two functions around that will be called in an upper level in my software:
void ignoreResultOfDifficultFunction_1(void) {
(void) myReallyDifficultFunction();
}
and
boolean needResultOfDifficultFunction(void) {
return( myReallyDifficultFunction() );
}
Here it is about the ignore-Function.
With defintion above I got the code compiled - all fine. But I found also following solution, which is said to be C++-Style:
void ignoreResultOfDifficultFunction_2(void) {
static_cast<void>( myReallyDifficultFunction() );
}
What I don't understand is the difference to casting, e.g.,
a_long = (long) a;
And, I guess, everbody is doing this, and not writing
a_long = static_cast<long>(a);
So, my question, what is the difference? As said, the only rationale I was able to find is C++ vs C, hm, ok, I get both compiled, so I'm confused as Arduino IDE is C++, isn't it? So why do get the simple cast (not using the C++ static_cast) compiled?
Thanks in helping me to further understand.