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

Which code is more correct?

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



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

Which code is more correct?
PostPosted: Mon Aug 17, 2009 2:59 am     Reply with quote

I tried these codes on CCS-C and two of them have worked. But I don't know which is more correct?

1)
Code:
#include <12F675.h>
#use delay(internal=4M)
#fuses NOWDT,INTRC_IO,PUT,NOPROTECT,BROWNOUT,NOMCLR,NOCPD



2)
Code:
#include <12F675.h>
#use delay(clock=4000000)
#fuses NOWDT,INTRC_IO,PUT,NOPROTECT,BROWNOUT,NOMCLR,NOCPD
Ttelmah
Guest







PostPosted: Mon Aug 17, 2009 5:11 am     Reply with quote

Why does there have to be a 'more correct' version?....

Both will produce exactly the same output.
It is a bit like asking whether it is 'more correct' to use a for...next loop, or a while loop. No difference at all.

The bottom one, will be accepted by a wider 'range' of compilers (the top one only by more recent ones). The top one makes it easier to avoid errors (it is quite easy with the '4000000' notation to 'miscount' the number of zeros by one). The top notation, was introduced, since especially with really large frequencies (48MHz etc.), it becomes hard to count all the zeros,and ensure the value is 'right'.

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