thetransltr (6) Nov 21, 2009 at 11:30pm UTC
Good day! Im a C++ beginner, can anybody explain to me how this 2 codes work?
#define _RGB16BIT565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))
#define _RGB32BIT(a,r,g,b) ( + ((g) << 8) + ((r) << 16) + ( << 24))
Bazzy (3182) Nov 21, 2009 at 11:30pm UTC
#define _RGB16BIT565(r,g,b) is defining a macro called _RGB16BIT565 with three parameters
The second part is some mathematical trick:
Last edited on Nov 21, 2009 at 11:30pm UTC
guestgulkan (1040) Nov 21, 2009 at 11:30pm UTC
Strange though - I thought the top one should be ((g%64) << 5) not ((g%64) << 6)
Last edited on Nov 21, 2009 at 11:30pm UTC
thetransltr (6) Nov 21, 2009 at 11:30pm UTC
Thanks for clearing that up for me. However im having problem understanding the parenthesis for example:
#define _RGB16BIT565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))
some opening parenthesis has no closing parenthesis which i think will give error but it didn't. Hows this syntax possible? Is creating a macro different?
Bazzy (3182) Nov 21, 2009 at 11:30pm UTC
some opening parenthesis has no closing parenthesis
All parentheses are matched, where do you see miss-matches?
Hows this syntax possible?Is creating a macro different?
Even if it was, you can have whatever you want in a macro
eg:
1 2 3 4 5 6 7 8 9 10
#define MACROS int main (
#define ARE ){
#define BAD return
#define DONT 0
#define USE ; }
#define THEM
MACROS ARE BAD!!!
DONT USE THEM
thetransltr (6) Nov 21, 2009 at 11:30pm UTC
Thank you guys!