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

expression question

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



Joined: 02 Feb 2010
Posts: 345

View user's profile Send private message

expression question
PostPosted: Thu Aug 01, 2013 7:03 am     Reply with quote

Hi all,
What means this expression
Code:
#define hi(x)  (*((int8 *)&x+1))
Ttelmah



Joined: 11 Mar 2010
Posts: 19329

View user's profile Send private message

PostPosted: Thu Aug 01, 2013 8:54 am     Reply with quote

An inefficient way of getting the high byte of a value.

Inefficient, since 'make8', can do the same in a single machine cycle, while this takes dozens....

It takes the address of the variable 'x' (&x). Treats this as if the variable was an int8 (int8 *), increments it by one (to get the address of the next byte '+1'), and then returns the contents of this address (*......).

Indirect addressing is inefficient on the PIC in general, taking several instructions to setup. Modern use is almost certainly is the result of somebody not 'knowing this', and porting code over from a chip where this doesn't apply, or from an example that pre-dates CCS adding the 'make8' instruction (which does this as efficiently as possibly

Unfortunately, some of the CCS examples, date from before this, so use this form.....

It is 'standard C'.

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