I have a question about bit operation in c++,
there is a set of code:
#define INDEX(SRC, DEST) ((U16)SRC | (DEST << 8))
what does this (U16)SRC | (DEST << 8) means?
I would guess U16 is also a macro somewhere in the code and it probably designates a 16-bit unsigned integer type(which I deduce from the abbreviation). SRC and DST are the two arguments to the macro expansion the code is defining and (U16)SRC | (DEST << 8) would mean that DEST gets bit shifted 8 bits to the left and then logical or-ed to SRC. Probably the code depends that both SRC and DEST are 8-bit values and this code creates a bit mask that is the result of the appending of the 8-bits of DEST to the 8-bits of SRC.
For instance if (in binary) DEST is 10010101 and SRC is 00001111 then the result is 1001010100001111.
With the code you showed it is a lot of guessing: sure, it looks as if U16 is a macro for unsigned short or uint16_t. If you want to find out, what the define expands to include the definition of the the macro and invoke the macro in a simple test program:
#include "whatever-defines-INDEX.h"
INDEX(10, 1)
Then invoke the compiler with the -Eoption (or the /E option if -E isn't available and you are using Windows): this sends the result of running the preprocessor to the standard output.
( SRC | ( DEST * 256 ) )INDEX(s1+s2,d1+d2)). In C++, you should nearly always use an inline function for something like this; if for some reason you have to use a macro, then make sure you put parentheses around every appearance of the macro arguments.