LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

return of void functions inconsistency between CVI 2013 and older

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.

 

0 Kudos
Message 1 of 7
(5,571 Views)

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.

S. Eren BALCI
IMESTEK
0 Kudos
Message 2 of 7
(5,561 Views)

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.

 

0 Kudos
Message 3 of 7
(5,558 Views)

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;
}

 

 

Daniel Dorroh
National Instruments
0 Kudos
Message 4 of 7
(5,485 Views)

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.

 

0 Kudos
Message 5 of 7
(5,478 Views)

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;
}

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 7
(5,462 Views)

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.

Daniel Dorroh
National Instruments
0 Kudos
Message 7 of 7
(5,434 Views)