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

Macro Explanation Please!

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








Macro Explanation Please!
PostPosted: Sun Jan 07, 2007 10:52 am     Reply with quote

Hi,

I am using these wonderful macros that I found on the board to deal with individual i/o pins:
Code:

#define set_bit_var(x)     bit_set(*(int8 *)(x >> 3), x & 7)
#define clear_bit_var(x) bit_clear(*(int8 *)(x >> 3), x & 7)
#define read_bit_var(x)   bit_test(*(int8 *)(x >> 3), x & 7)


As a relatively new and curious programmer, I was wondering if anyone could explain to me the various asterisks that appear in the define statements as, although I do understand pointers, I am not sure quite why two asterisks and an 'int8' are needed here?!

Many thanks in advance! Smile

John
Ttelmah
Guest







PostPosted: Sun Jan 07, 2007 10:58 am     Reply with quote

#define set_bit_var(x) bit_set(*(int8 *)(x >> 3), x & 7)

OK. The first '*', says 'use this pointer'. The second is a 'cast'. The little bit in the bracket, 'converts' the value that follows, 'into' a pointer of type 'int *' (pointer to an integer). Up to this point, what follows, is an integer. the bracketted bit, tells the compiler to treat this integer as if it was a pointer. The first *, then uses this as a pointer!.

Best Wishes
Guest








Thank you!
PostPosted: Sun Jan 07, 2007 11:07 am     Reply with quote

Brilliant, a concise and crystal clear explanation - now my curiosity is satisfied - thank you very much! Very Happy

Regards,

John
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