CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

multiplication bug

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lor3nzo
Guest







multiplication bug
PostPosted: Thu Nov 13, 2008 5:04 am     Reply with quote

Hi,
I'm using pcw 4.032 and the instruction
var=var*5
doesn't work, but I have the correct result with
var=var+var+var+var+var.

Why?
Thank you
Ttelmah
Guest







PostPosted: Thu Nov 13, 2008 5:09 am     Reply with quote

Questions:
What type is 'var'?.
What value is in 'var', when you see the problem?.
Have you looked at the 'sticky' thread at the top of the forum, on 'version 4 coments'. 4.032, is 'borderline', on being a useable version. I'd not have expected something as basic as multiplication to actually give a problem - more likely, something else is failing, and being 'seen' as a problem in the multiplication....

Best Wishes
Guest








PostPosted: Thu Nov 13, 2008 5:19 am     Reply with quote

var is a int16 variable.

This instruction doesn't work too
var1=var2*5
the two variable are int16
var1 is 0 and var2 is 6.
lor3nzo
Guest







PostPosted: Thu Nov 13, 2008 5:23 am     Reply with quote

I've this problem with a 18F2321.
I reused this portion of code in a project with a 16f648a and everything is alright.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Nov 13, 2008 5:44 am     Reply with quote

You are missing a semicolon var1=var2*5; <---- Laughing

Is this your code ?
Code:

main()
{
  int16 var1, var2;

  var2 = 6;
  var1 = var2 * 5;
  printf("%Lu, %Lu\r\n", var1, var2);
  while(true) {}
}

?

If not WHAT is your code ?
How are you looking at the values var1 and var 2 ?
lor3nzo
Guest







PostPosted: Thu Nov 13, 2008 7:26 am     Reply with quote

That is the code.
I watch variables with debug mode.
Ttelmah
Guest







PostPosted: Thu Nov 13, 2008 9:26 am     Reply with quote

I think you will find that your problem is in the debug, rather than the multiplication. I seem to remember some (several) threads running at about the time that the early V4.03x compilers came out, with problems like this. Try a physical output, like Wayne is showing, and I suspect you will find that the values are fine.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group