IPB

Welcome Guest ( Log In | Register )

> Makeshort And "local Variable May Be Used Uninitialized" Warning
FredericG
post Dec 30 2007, 06:59 PM
Post #1


Newbrie


Group: EstablishedMember
Posts: 14
Joined: 18-February 07
Member No.: 2,937



A macro like MAKESHORT can initialize a variable but the compiler does not know that and generates a warning. Is there a way to solve this without initializing the variable explicitly?

Frederic
update SourceBoost release 6.97 is available.
Download Now
Go to the top of the page
 
+Quote Post
 
Start new topic
Replies
Dave
post Dec 31 2007, 12:26 PM
Post #2


Super Maniac
*****

Group: Administrators
Posts: 1,830
Joined: 28-September 04
From: UK
Member No.: 469



FredericG,
QUOTE (FredericG @ Dec 30 2007, 06:59 PM) *
A macro like MAKESHORT can initialize a variable but the compiler does not know that and generates a warning. Is there a way to solve this without initializing the variable explicitly?
Please provide an example of what you mean exactly.

Regards
Dave
Go to the top of the page
 
+Quote Post
FredericG
post Dec 31 2007, 05:44 PM
Post #3


Newbrie


Group: EstablishedMember
Posts: 14
Joined: 18-February 07
Member No.: 2,937



QUOTE (Dave @ Dec 31 2007, 01:26 PM) *
FredericG,
Please provide an example of what you mean exactly.
Regards
Dave



u16_t timestamp;

t1con.TMR1ON = 0; // stop timer
MAKESHORT(timestamp, tmr1l, tmr1h);

en_of_pulse = timestamp; <<==== causes warning

QUOTE
It's not the macro that's the problem, but the inline assembly it uses. The compiler doesn't notice if you set a variable with inline assembly statements and warns that it's possibly uninitialized. Declaring the variable as 'volatile' gets rid of the warning, but isn't a great solution as you might miss a true 'uninitialized' case.

I am not an expert, but I think I have seen compilers that have pragma's that give hints to compiler about these things.
Thanks for the workaround, I can for sure live with that solution

Frederic
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 3rd September 2010 - 02:47 PM