Jump to content

Makeshort And "local Variable May Be Used Uninitialized" Warning


Recommended Posts

FredericG,

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

Link to post
Share on other sites
FredericG,
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

 

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.

 

Orin.

Link to post
Share on other sites
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

 

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

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...