[RC5] Golomb stuff/Void souls

gindrup at okway.okstate.edu gindrup at okway.okstate.edu
Thu Mar 5 09:39:48 EST 1998


     Direct reply.
     
     This distinction between type conversion and casting has dissolved 
     over the course of standardization.  Now the C-style casts wotk only 
     on intrinsic types.  Function notational casts work both for 
     intrinsic types and operator <type>() type conversions, but are now 
     called casts (since the distinction wasn't particularly meaningful 
     and C-style casts are deprecated).  The third set of casts, 
     "new-style casts" aren't in Stroustrup 2nd ed, but are in 3rd ed.
     
     Some days I wish the cast/type conversion distinction had been kept 
     and some days I don't...
            -- Eric Gindrup ! gindrup at Okway.okstate.edu


______________________________ Reply Separator _________________________________
Subject: Re: [RC5] Golomb stuff/Void souls 
Author:  <rc5 at llamas.net > at SMTP
Date:    3/5/98 3:41 AM


'Ryan Anderson' said previously:
     
     
| "With this word of power, I cast thy soul into the void: void(soul)"
     
[...]
     
| Anyone who truly
| knows, please respond and settle the question...
     
<BODY MODE="language lawyer">
     
Ok, I'm at home now, and I have a copy of _The C++ Programming 
Language_, 2nd Ed., by Bjarne Stroustrup himself.  :-)  I'd hope it'd 
be close to being a definitive reference.  :-)  Sure, the 
standardization effort takes precedence, but I'd dare say Stroustrup is 
pretty reliable.  (Notational note:  Words written /like this/ are in 
"italics".)
     
>From section r.5.2.3, pg 495:
     
    r.5.2.3 Explicit Type Conversion
     
    A /simple-type-name/ followed by a parenthesized /expression-list/ 
    constructs a value of the specified type given in the expression 
    list.  If the expression list specifies more than a single value, 
    the type must be a class with a suitably declared constructor.
     
    A /simple-type-name/ followed by a (empty) pair of parentheses 
    constructs a value of the specified type.  If the type is a class 
    with a suitably declared constructor that constructor will be 
    called; otherwise the result is an undefined value of the specified 
    type.  See also Section r.5.4.
     
In layman's terms, typename(expression-list) peforms type conversion by 
suitably calling the constructor for the resulting type.  This is not, 
however, a cast.  Cast expressions are described in Section r.5.4.
     
>From section r.5.4, pg 500:
     
    r.5.4 Explicit Type Conversion
     
    An explicit type conversion can be expressed using either 
    functional notation (r.5.2.3) or the /cast/ notation.
     
        /cast-expression:/
                /unary-expression/
                ( /type-name/ ) /cast-expression/
     
    The /cast/ notation is needed to express conversion to a type that 
    does not have a /simple-type-name/.
     
    [....]
     
    Any type conversion not mentioned below and not explicitly defined 
    by the user (r.12.3) is an error.
     
In other words,  (typename)expression is a cast, and it performs 
explicit type conversion.  typename(expression) is the functional 
notation for explicit type conversion, and it works only when typename 
is a simple-type-name.  But, it is not a cast, insofar as "cast" 
describes the old C style syntax.  The new syntax appears to exist to 
support multi-argument constructors -- eg.  complex(x,y) might 
construct an object of type "complex", accepting the values "x" and "y" 
as the real and imaginary components.
     
So, to say you're "casting thy soul into the void", you'd need to write 
it as "(void)soul".  The alternate syntax merely means you're 
explicitly converting thy soul to void, which isn't nearly as
humorous.  :-)
     
--Joe
     
</BODY>
-- 
 +----------- Joseph Zbiciak ----------+  Eliminate idle cycles!
 | - - - -  j-zbiciak1 at ti.com  - - - - |  http://www.distributed.net/ 
 |- http://www.primenet.com/~im14u2c/ -| 
 | - - -Texas Instruments, Dallas- - - |  "Give them a light, and they'll 
 +-----#include "std_disclaimer.h"-----+   follow it anywhere." -- Firesign
--
To unsubscribe, send 'unsubscribe rc5' to majordomo at lists.distributed.net 
rc5-digest subscribers replace rc5 with rc5-digest
     
     
--
To unsubscribe, send 'unsubscribe rc5' to majordomo at lists.distributed.net
rc5-digest subscribers replace rc5 with rc5-digest



More information about the rc5 mailing list