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

Data Types in PCWH

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







Data Types in PCWH
PostPosted: Tue Dec 16, 2003 1:57 pm     Reply with quote

Greetings,

I'm having a simple but frustrating difficulty with the CCS PCWH compiler on the PIC18F8720. I'm simply trying to have a counter run up to 65535, then roll over and repeat. The code works fine under GNU C. I skimmed the manual and changed the unsigned int to int16, as shown below. But, for whatever reason, CCS treats the variable as an unsigned 8 bit integer, and only compiles if I use %X instead of %u. With %u, the printf generates an error. Code and error follow:

Code:

main() {
int16 i ;
printf("Count:") ;

while(1) {
for(i = 0 ; i <= 65535 ; i++)
printf(" %u", i) ;
}
}

Error from CCS:
Printf Format Type is invalid

I'm sure there's a glaring and quite obvious solution to all this, but I cannot see it. Can someone please help?

Thanks!
Bridger T. Wray
Mark



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

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

PostPosted: Tue Dec 16, 2003 2:45 pm     Reply with quote

Try %lu instead.


Regards,
Mark
miltiades



Joined: 16 Dec 2003
Posts: 1

View user's profile Send private message

PostPosted: Tue Dec 16, 2003 2:56 pm     Reply with quote

Mark,

Thanks, %lu works well. I'm still a little frustrated with these compiler quirks and slight differences with ANSI C. I'm sure these will disappear with experience though.

Thanks again for the prompt response,
bridger
Ttelmah
Guest







PostPosted: Tue Dec 16, 2003 3:59 pm     Reply with quote

miltiades wrote:
Mark,

Thanks, %lu works well. I'm still a little frustrated with these compiler quirks and slight differences with ANSI C. I'm sure these will disappear with experience though.

Thanks again for the prompt response,
bridger

It is perhaps worth remembering, that this is C, not ANSI C.
The original Kernighan and Ritchie books for C, specifically say, that an 'int' will be the standard data type for the processor concerned, giving examples of chips with very different default integer sizes.
Now, ANSI C, specifically 'stepped away' from this, to increase code portability, but by doing so, introduces the need to specifically code to the most efficient type, for best speed.
You are much better off using the standard 'K&R' definitions for this C, which are 99% followed.

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