/* lvalue_cast<> code by Jonathan Lennox , * placed in the public domain. */ template Targ& lvalue_cast(Src& s) { union { Src * s; Targ * t; } u; u.s = &s; return *u.t; /* GNU Extension */ } /* Test case by Ziemowit Laski */ #include #define CHECK_IF(expr) if (!(expr)) abort () static int global; void f(int &) { global = 35; } void f(const int &) { global = 78; } long long_arr[2]; int main(void) { char *p; lvalue_cast(p) = long_arr; lvalue_cast(p)++; *(long *)p = -1; *p = -2; CHECK_IF(p[-1] == 0 && p[0] == -2 && p[1] == -1); long x = 0; f((int)x); CHECK_IF(global == 78); return 0; }