Page 1 of 1

Backend Compiler Warning

Posted: 06 October 2008, 17:50 PM
by Don_Kirby
I've been getting this warning while now (it's not due to the newest compiler release). The application functions properly by all accounts, although the particular function where the warning is coming from is as yet unfinished.
ModbusTask.c: In function 'zf_ModbusTask':
ModbusTask.c:28: warning: 'zv_DataCount' may be used uninitialized in this function
The warning is issued even if the variable is manually given a value immediately after declaration, such as:

Code: Select all

	Dim I as Integer
	Dim BitTIme as Single
	Dim AddressField as Byte
	Dim OldQCount as Integer
	Dim DataCount as Integer
	DataCount = 1
	
	Dim CRC as UnsignedInteger
	Dim	ReceivedCRC as UnsignedInteger
The corrosponding C code does not seem to set the variable at all:

Code: Select all

	int16_t zv_I;
	float zv_BitTIme;
	int16_t zv_OldQCount;
	int16_t zv_DataCount;
	uint16_t zv_CRC;
	uint16_t zv_ReceivedCRC;
I'm not necessarily concerned about the warning, but for the sake of commenting my code, I'd like to identify the issue, and at the very least make note of it.

-Don

Re: Backend Compiler Warning

Posted: 06 October 2008, 18:10 PM
by dkinzer
Don_Kirby wrote:I'd like to identify the issue, and at the very least make note of it.
In most cases that I've seen, the warning that you referred to is valid. I have seen a few cases where the logic guaranteed that the variable wouldn't be used unless it was initialized.

In any event, I'd like to see the ZBasic code that led to this warning so that I can see what can be done to eliminate it.

Posted: 07 October 2008, 14:58 PM
by Don_Kirby
I'll see if I can come up with a small test case that exhibits the problem.

-Don

Posted: 07 October 2008, 15:12 PM
by Don_Kirby
In trying to isolate the problem, I've determined that when the task is taken out of the context of the application, the warning goes away. I'll need to do a bit more work to get a smaller test application to behave the in the same manner as the entire application.

Two other things:

It seems that the compiler is incorrectly reporting the amount of persistent memory in use:
No errors. Target device: ZX24n, Code: 39166 bytes, RAM: 1713 bytes, Persistent memory: 32 bytes
It should be over 900 bytes. This is almost certainly not related to the warning issue.

Also, if I double click on the warning in the compiler output pane, the IDE jumps to the offending line number in the ZBasic code, which doesn't correspond at all to the C code to which the warning is referring to.

-Don

Posted: 07 October 2008, 17:47 PM
by dkinzer
Don_Kirby wrote:I'll need to do a bit more work to get a smaller test application to behave the in the same manner as the entire application.
If you don't mind sending me the whole application, I can work directly with it. That way, you won't have to spend time trying to reproduce it in a small test case.