Backend Compiler Warning

Discussion of issues related specifically to writing code for native mode devices. This includes ZBasic code as well as assembly language code and C code, both inline and standalone.
Post Reply
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Backend Compiler Warning

Post 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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: Backend Compiler Warning

Post 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.
- Don Kinzer
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post by Don_Kirby »

I'll see if I can come up with a small test case that exhibits the problem.

-Don
Don_Kirby
Posts: 341
Joined: 15 October 2006, 3:48 AM
Location: Long Island, New York

Post 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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Post 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.
- Don Kinzer
Post Reply