View previous topic :: View next topic |
Author |
Message |
matrixofdynamism
Joined: 06 Dec 2010 Posts: 25
|
What is the difference between #byte and #locate? |
Posted: Sun Apr 03, 2016 5:25 pm |
|
|
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, |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Mon Apr 04, 2016 12:01 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
matrixofdynamism
Joined: 06 Dec 2010 Posts: 25
|
|
Posted: Mon Apr 04, 2016 5:43 am |
|
|
When you say that the useage has declined, does it mean it has declined specifically in CCS PIC C compiler? Why is that so? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Mon Apr 04, 2016 6:22 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Thu Apr 07, 2016 10:01 am |
|
|
#LOCATE define an address for exclusive use; #byte the address can be shared. _________________ Electric Blue |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19381
|
|
Posted: Thu Apr 07, 2016 11:10 am |
|
|
I know it says that, but try it. You can #locate multiple values at the same location, and it won't complain.... |
|
![](templates/subSilver/images/spacer.gif) |
E_Blue
Joined: 13 Apr 2011 Posts: 417
|
|
Posted: Thu Apr 07, 2016 1:12 pm |
|
|
Maybe have not that foolprof protection. ![Neutral](images/smiles/icon_neutral.gif) _________________ Electric Blue |
|
![](templates/subSilver/images/spacer.gif) |
|