/* LVALUE_CAST code by Jonathan Lennox , * placed in the public domain. */ #define LVALUE_CAST(TYPE, OBJ) (*({ \ union { __typeof__(OBJ) * s; TYPE * t; } u; \ \ u.s = &OBJ; \ u.t; /* GNU Extension */\ })) /* Test case by Ziemowit Laski */ #include #define CHECK_IF(expr) if (!(expr)) abort () int main(void) { char *p; long l; short s; LVALUE_CAST(long *, p) = &l; /* ok */ LVALUE_CAST(long *, p)++; /* ok */ LVALUE_CAST(short, l) = 2; /* Result depends on endianness. */ LVALUE_CAST(long, s) = 3; /* Stack clobber; run-time undefined behavior. */ return 0; }