|
|
View previous topic :: View next topic |
Author |
Message |
bridger Guest
|
Data Types in PCWH |
Posted: Tue Dec 16, 2003 1:57 pm |
|
|
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
|
|
Posted: Tue Dec 16, 2003 2:45 pm |
|
|
Try %lu instead.
Regards,
Mark |
|
|
miltiades
Joined: 16 Dec 2003 Posts: 1
|
|
Posted: Tue Dec 16, 2003 2:56 pm |
|
|
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
|
|
Posted: Tue Dec 16, 2003 3:59 pm |
|
|
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 |
|
|
|
|
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
|