10-01-2014 09:46 AM
Hello,
I have discovered an inconsistency using CVI 2013 (SP2 or not) compared to CVI 2010 and CVI 8.5 (the versions I have).
I have written, by mistake, a code where I'm returning a value for a void function. CVI 2013 does not complain (but should) while other CVI versions complain (and that's OK).
Here is the code:
static void pouet(void) { return; } static void hop(void) { return pouet(); } int main(void) { hop(); return 0; }
Could this behaviour be fixed for the next CVI update ?
Thanks.
Frédéric Lochon.
10-01-2014 10:18 AM
Hi Fred,
What do you mean by "complain", a warning or an error?
I tried it in 2013 SP1, and it generates a warning. And on 2012 it caused a build error.
If it is not even generating a warning, then probably it is about compiler warning configuration, which you can change from Build Options window.
But generating a warning instead of an error may be the intended behavior.
Probably they changed the compiler deliberately and it no longer causes an error.
10-01-2014 10:29 AM
Hum...
Whatever my "warning level" is, I don't get any warning or errors on the 2 machines I have which are running CVI 2013 SP2.
It looks like there is some magical option which is different here...
I can understand they changed the behaviour to avoid "errors", but I would expect, at minimum, a warning.
Best regards.
10-06-2014 04:59 PM - edited 10-06-2014 05:06 PM
Hi ebalci,
Which warning did you see in 2013 SP1? I compiled the code provided by Fred with warnings set to All, and did not see any warnings. In 2010, the build fails with an Extraneous return value
error, pointing to the return value of hop
.
Edit: Another interesting observation is that if you change the definition of pouet
to the following, 2013 returns a void function 'hop' should not return a value
warning:
static int pouet(void) { return 0; }
10-06-2014 11:36 PM
Hi D-Cubed,
This is exactly the behaviour I have on my side.
I guess CVI 2013 doesn't complain when a void function returns a void. I'm not a C guru but I don't know if it's permitted (I guess probably not, as gcc emits a warning in such cases).
Frédéric.
10-07-2014 08:36 AM - edited 10-07-2014 08:36 AM
Well it's technically not causing wrong behaviour, but may cause less than best performance depending on the compiler code generation as the register usually used for function return values might be assigned some garbage value that never will get used though.
Causing an error is likely a bit strict, issueing a warning would be the prefered behaviour, not generating either a warning or error is a bit lazy. Problematic would be if you could write this without getting an error:
static void pouet(void) { return; } static int hop(void) { return pouet(); } int main(void) { hop(); return 0; }
10-08-2014 02:08 PM
A void function returning a call to a void function and not generating a compile error or warning is expected behavior in LabWindows/CVI 2013. In this case, we are returning an expression of type void as the return value of a function that is also of type void. There is no inconsistency, so there is no warning and no error.
However, we do return an error for other cases discussed in this thread. For example, the code rolfk posted returns the error: returning 'void' from a function with incompatible result type 'int'
, and the build fails.
I realize that the behavior is different from the past, but with 2013 came a brand new compiler, so not everything behaves exactly as it used to.