When I examined the definition of the container_of
macro in Linux Kernel,
I saw a compound statement as a macro definition,
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
however the unclear issue in my mind is which statement gets taken into account as rvalue. Apparently result of the last statement is used as rvalue, but why?
(type *)( (char *)__mptr - offsetof(type,member) );
For instance, is the code example below legal in C?
int g_count = 0xFF;
#define GLOBAL_COUNT do {g_count;} while(0)
int main(int argc, char *argv[])
{
int local;
local = GLOBAL_COUNT;
local = 0;
GLOBAL_COUNT = local;
return 0;
}
What is the assignment rule for variables in compound statements?