|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Macro Explanation Please! |
Posted: Sun Jan 07, 2007 10:52 am |
|
|
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!
John |
|
|
Ttelmah Guest
|
|
Posted: Sun Jan 07, 2007 10:58 am |
|
|
#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! |
Posted: Sun Jan 07, 2007 11:07 am |
|
|
Brilliant, a concise and crystal clear explanation - now my curiosity is satisfied - thank you very much!
Regards,
John |
|
|
|
|
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
|