View Single Post
  #1   Spotlight this post!  
Unread 17-02-2005, 23:20
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
Nasty Compiler Bug

So the past couple weeks we've been working on our autonomous code on a test robot. Over this time we've been having problems and wracking our brains about outputs that just don't seem to make sense. I managed to track down at least one of the problems today and it appears to be a compiler bug. This is not a request for help but just trying to inform everyone else of the issue.

If you use the following statement:
Code:
long coeff_1 = 90/2*40;
coeff_1 will equal 8. Now this is obviously not the correct value (it should be 1800). For some reason, the compiler appears to do math in initalization statements (for long's at least) in a 8-bit space (1800 = 8 in an 8-bit space).

If you use this code:
Code:
long coeff_1 = 1800;
it will work correctly.

The long and the short of it is to always do any math out before putting it in the source code. While it's more work for you, it results in correctly generated code.

I'm not sure where to report this bug to Microchip so if anyone knows, please tell me.

Matt