Re: [GD-General] The joy of type aliasing and C
Brought to you by:
vexxed72
|
From: Brian H. <ho...@py...> - 2003-12-31 17:06:53
|
> would work just as well. Now, this depends on definition of lvalue. >From 6.3.2.1: "An lvalue is an expression with an object type or an incomplete type other than void; if an lvalue does not designate an object when it is evaluated, the behavior is undefined....a modifiable lvalue is an lvalue that does not have array type, does not have an incomplete type, does not have a const-qualified type, and if it is a structure or union, does not have any member with a const-qualified type." >From footnote 53: "The name 'lvalue' comes originally from the assignment expression E1 =3D E2, in which the left operand E1 is required be a (modifiable) lvalue." > Perhaps (const int &) might be considered an lvalue, but according int x =3D ( int & ) f; int x =3D * ( int * ) &f; In the above, both the 'f' are considered lvalues, since they are expressions with an object type. > What might be of more interest is: What does C++98 say on using > reinterpret_cast? > > i =3D reinterpret_cast<int&>(f); That is semantically identical to a direct cast as in C and is equally unsafe since there is no guarantee that the bit representation of 'f' will be meaningful as an integer. That said, it does work on the compilers I've tried =3D) > The reinterpret_cast operator is _designed_ to be used for type > punning, isn't it? Typically only for modifying pointer types, e.g. derived pointer to base class, etc. Brian |