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

Compiler bug or programming error?

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



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

Compiler bug or programming error?
PostPosted: Sat Apr 16, 2005 11:14 am     Reply with quote

// CCS compiler 3.218

#include <18F452.h>

long present_day_of_year_number;

byte present_day;

-
-
-
-

present_day = 0b00010110; // = 16 (BCD test data)


// this way produces output of 0:

present_day_of_year_number = (long)( 10*(present_day>>4) + present_day&0x0F );

printf("\r Pres. DOY# : %ld", present_day_of_year_number);


// however this way produces proper output of 16:

present_day_of_year_number = (long)(10*(present_day>>4) );
present_day_of_year_number += (long) (present_day&0x0F);

printf("\r Pres. DOY# : %ld", present_day_of_year_number);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Apr 16, 2005 12:38 pm     Reply with quote

Quote:
// this way produces output of 0:
present_day_of_year_number = (long)( 10*(present_day>>4) + present_day&0x0F );


Look at a table of operator precedence. This will show you the problem.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_c.2b2b_.operators.asp
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Sat Apr 16, 2005 12:52 pm     Reply with quote

Yes -adding parentheses did it.

Thanks!


present_day_of_year_number = (long)( 10*(present_day>>4) + (present_day&0x0F) );
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