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

What is the difference between #byte and #locate?

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



Joined: 06 Dec 2010
Posts: 25

View user's profile Send private message

What is the difference between #byte and #locate?
PostPosted: Sun Apr 03, 2016 5:25 pm     Reply with quote

Both seem to be doing the same thing, so what is the difference between them since if these are 2 separate preprocessor directives, there must be things unique about them,
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Apr 04, 2016 12:01 am     Reply with quote

For 99.9% of things you can use either.
The reason for both is basically 'historic'. Most compilers have a #locate. CCS originally had a #byte that would automatically create a byte sized variable. Then #byte was extended to allow other things to be located by it, and #locate was was extended to also automatically create a byte sized variable if it was called without an existing variable.
Result, both functions function basically the same.

I tend to use them 'as originally intended', so use #byte to only create byte sized variables at specific locations, #word to create int16 variables at specific locations, and #locate to locate anything else. This way the declaration contains a 'hint' to what you are actually doing.
However the need for these has declined sharply in recent years, so #byte for the odd processor register is about the only need that really exists.
matrixofdynamism



Joined: 06 Dec 2010
Posts: 25

View user's profile Send private message

PostPosted: Mon Apr 04, 2016 5:43 am     Reply with quote

When you say that the useage has declined, does it mean it has declined specifically in CCS PIC C compiler? Why is that so?
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Apr 04, 2016 6:22 am     Reply with quote

Because now you can access 99.9% of all chip features, without ever having to go DIY.
Just about every setting possible in the chips is available through the CCS functions.

Back when I first wrote CCS code, 80% of code would at some point involve a direct access of some sort. Ten years ago, perhaps 10% of code would at some point involve going direct. On the last dozen programs I have done, I haven't had to go direct even once.
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 10:01 am     Reply with quote

#LOCATE define an address for exclusive use; #byte the address can be shared.
_________________
Electric Blue
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 11:10 am     Reply with quote

I know it says that, but try it. You can #locate multiple values at the same location, and it won't complain....
E_Blue



Joined: 13 Apr 2011
Posts: 417

View user's profile Send private message

PostPosted: Thu Apr 07, 2016 1:12 pm     Reply with quote

Maybe have not that foolprof protection. Neutral
_________________
Electric Blue
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