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

Unexpected #type int=n sideffect with PCD/PCH/PCM

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



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

Unexpected #type int=n sideffect with PCD/PCH/PCM
PostPosted: Sun Dec 28, 2008 4:05 pm     Reply with quote

Hello,

with a #type int=n directive in effect, the unsigned keyword in the below variable definition is ignored and the compare never executed by PCD (Versions up to V4.084). Any explanations?

Code:
#type int=16
unsigned int16 dt;
if (++dt >= 1800*24)
  dt = 0;


Last edited by FvM on Mon Dec 29, 2008 1:22 am; edited 1 time in total
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 4:26 pm     Reply with quote

Quote:
#type int=16
unsigned int16 dt;
if (++dt >= 1800*24)
dt = 0;


Unless I am missing something #type int=16 should have no effect on a
direct int16 declaration.

As it is written in your example (++dt >= 1800*24) will never execute so
I assume there must be more code in there somewhere. I have PCWH
not PCD so I can't check this.

Have you tried to do some direct assignment experiments to see what
size dt really is? (i.e. dt = 40000 then display the result to confirm).
Try 32000, 33000, 65000 and 66000 to see the results.

.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 4:41 pm     Reply with quote

There isn't more code. It's not the specific int=n size, it's the simple existence of the #type int= statement, that causes the issue. And it's apparently specific to PCD. With this statement in effect, unsigned int16 is treated as int16, a signed keyword is also ignored then, b.t.w.

Code:
#include <24FJ128GA106.h>
#type int=16
unsigned int16 dt;
void main(void)
{
   while (1)
   {
      if (++dt >= 1800*24)
         dt = 0;
   }   
}
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 5:48 pm     Reply with quote

Interesting.... Although, FWIW int16 is the same as unsigned int16. The
default for integers is unsigned in CCS. See below from the CCS manual.

Quote:
Note: All types, except float, by default are
unsigned; however, may be preceded by unsigned or signed.


I'll try this in PCWH to see what happens...

EDIT UPDATE:
After doing some testing I found the same result in PCWH. Adding the line
#type int=16 makes all integers unsigned and overrides any signed
declarations. Simply commenting out this line returns everything to
normal. This may be as designed but I can't find it in the manual.

FVM, Are you going to report this to CCS?


.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Dec 29, 2008 1:12 am     Reply with quote

Thanks for your extended tests.

The difference is, that PCH has a default of unsigned for int types while PCD has a default of signed. I didn't remember this difference. In both cases, the #type int= statement invalidates the preceeding signed/unsigned of a variable definition. The below code template allows to test the different behaviour. In each case, an error message Variable of this data type is never greater than this constant indicates an ignorance of the signed/unsigned definition.

Code:
//#include <24FJ128GA106.h>
//#include <18F4620.h>
#include <16F688.h>
//#type signed
//#type signed
#type int=16
unsigned int16 dt=0;
signed int16 dts=0;

void main(void)
{
   while (1)
   {
      if (++dt >= 1800*24)
         dt = 0;
      if (++dts < -1800*24)
         dts = 0;
   }   
}

Yes, I'll report this to CCS.

Best regards,
Frank
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Dec 29, 2008 7:51 am     Reply with quote

It's interesting that they changed the signed/unsigned default in PCD.

Also, I don't get the message "Variable of this data type is never greater than this constant" in PCWH.
This apparently was added only in PCD. Folks going from PCH to PCD are going to have fun with these differences!
I don't remember any significant issues of that sort at all gong from PCM to PCH (other than bug fixes).

Dave
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Dec 29, 2008 9:41 am     Reply with quote

The change to default signed int type in PCD is a move towards the C-standard, I think.

I get the said greater than this constant warning also with PCH, PCM and PCD, also the compiler removes the compare code in this case. So far the behaviour appears similar with all compiler variants.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Tue Dec 30, 2008 1:11 am     Reply with quote

CCS support tells:
Quote:
The problem you reported has been fixed and will be in the
next compiler release.
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