40 lines
742 B
C
40 lines
742 B
C
#include <stdio.h>
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
|
|
#define container_of(ptr, type, member) ({ \
|
|
const typeof(((type*)0)->member)* __mptr = (ptr); \
|
|
(type*)((char*)__mptr - offsetof(type, member)); })
|
|
|
|
struct A;
|
|
struct B;
|
|
|
|
struct A {
|
|
char m0;
|
|
int m1;
|
|
struct B* m2;
|
|
};
|
|
|
|
struct B {
|
|
int m0;
|
|
char m1;
|
|
short m2;
|
|
struct A* m3;
|
|
float m4;
|
|
struct A m5;
|
|
struct B* m6;
|
|
} __attribute__((slr));
|
|
|
|
int main(int argc, char** argv) {
|
|
struct A a = { 'x', 52, NULL };
|
|
struct B b = { 1, 2, 3, NULL, 4.f, a, NULL };
|
|
|
|
b.m2 = 42;
|
|
|
|
struct B* someB = (struct B*)malloc(sizeof(struct B));
|
|
float* someB_m4 = &someB->m4;
|
|
container_of(someB_m4, struct B, m4)->m1 = 'x'; // the "sub 0x..." is currently not recognized via ADDR_EXPR
|
|
|
|
return 0;
|
|
}
|