Re: The joy of type aliasing and C

Brian Hook <[email protected]>
Newsgroups gmane.games.devel.general
Message-ID <2003123112642.621854@GATEWAY>
> 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 
= 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 = ( int & ) f;
int x = * ( 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 = 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 =)

> 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




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
_______________________________________________
Gamedevlists-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-general
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_idU7
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.