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 support@ccsinfo.com

Constant out of the valid range

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



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

Constant out of the valid range
PostPosted: Wed Jan 12, 2005 2:37 pm     Reply with quote

Hi...Anybody figure it out?

I am using 18F4525 and CCS PCH Compiler.

I want to make one line of code instead of following two lines.
Where
int16 NewRPM;
int8 CylNum;
int32 TimerCycle;

Quote:

TimerCycle=TimerCycle/4;

NewRPM = (int16)(600000000/(TimerCycle*CylNum) );


If I make it like following

Quote:

NewRPM = (int16)(2400000000/(TimerCycle*CylNum) );


then it is giving error

Quote:

Constant out of the valid range -1894967296 is not 0..4294967295


This means 2400000000 is not in the range of 0..4294967295

How come this ?

Is there any other way to combine above two line of code.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 12, 2005 3:37 pm     Reply with quote

It appears that CCS constants are signed 32-bit integers, not unsigned.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Jan 12, 2005 5:06 pm     Reply with quote

It seems like an internal compiler bug to me where the compiler is working with signed 32-bit integers instead of unsigned (in an ANSII compiler this would be the correct behaviour, but CCS has all variables unsigned by default)..
The specified constant is an unsigned integer and fits in the range specified in the error message, so I consider this a compiler error.

A dirty workaround:
Code:
NewRPM = (int16)(((signed int32)2400000000)/(TimerCycle*CylNum) );


Please email this in a bug report to support@ccsinfo.com
prayami



Joined: 22 Dec 2004
Posts: 78

View user's profile Send private message

PostPosted: Wed Jan 12, 2005 9:08 pm     Reply with quote

Hi..

Thanks for reply. But as my number 2400000000 is positive then it must
fit with unsigned int32 bit. And if you check the number carefully it is
bigger than signed int32 bit. So if I cast it to signed int32 then,
it disturbed my RPM calculation.

Error:
Constant out of the valid range -1894967296 is not 0..4294967295

If you focus on error. Then it seems that compiler is not treating it like
unsigned int32. So casting it into signed int32 can solve the compilation
error but turns to give wrong RPM calculation as my number is bigger than
signed int32.

Is it really bug? Can you please try in your program?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jan 12, 2005 9:52 pm     Reply with quote

More efficient to do this:

NewRPM = (1171875/(TimerCycle*CylNum) );
NewRPM *= 2048;
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jan 13, 2005 2:31 am     Reply with quote

Quote:
Thanks for reply. But as my number 2400000000 is positive then it must
fit with unsigned int32 bit. And if you check the number carefully it is
bigger than signed int32 bit. So if I cast it to signed int32 then,
it disturbed my RPM calculation.

Your calculation is not disturbed using my workaround. I called it a 'dirty workaround' because it uses a feature of the cast operator. The cast operator changes a variable from a certain type to any other type you specify without doing any conversion of the internal value. Basically the cast operator is a very dangerous operator because you take a way control from the compiler. Here it works because both signed and unsigned int32 variables have the same internal data size.

I made a small test program and checked the resulting assembly code. Works great!

Still, I consider the error message a compiler bug and should be reported to CCS. If you are unsure, just mail it to them and have them decide what to do with it.
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