What is Expressiveness in a Computer Language

Darren New dnew at san.rr.com
Tue Jun 20 13:38:15 EDT 2006


Rob Thorpe wrote:
> Darren New wrote:
>>Rob Thorpe wrote:
>>>The values themselves have no type information associated with them.
>>int x = (int) (20.5 / 3);
> In that case it knew because it could see at compile time.

Well, yes. That's the point of static typing.

>  In general though it doesn't.

Sure it does. There are all kinds of formal rules about type promotions 
and operator version selection.

In deed, in *general* every value has a type associated with it (at 
compile time). Some values have a type associated with them due to the 
declaration of the variable supplying the value, but that's far from the 
general case.

Note that in
main() { char x = 'x'; foo(x); }
the value passed to "foo" is not even the same type as the declaration 
of "x", so it's far from the general case that variables even determine 
the values they provide to the next part of the calculation.

> If I divide x / y it only knows which to use because of types declared
> for x and y.

Yes? So? All you're saying is that the value of the expression "x" is 
based on the declared type for the variable "x" in scope at that point. 
That doesn't mean values don't have types. It just means that *some* 
values' types are determined by the type of the variable the value is 
stored in. As soon as you do anything *else* with that value, such as 
passing it to an operator, a function, or a cast, the value potentially 
takes on a type different from that of the variable from which it came.

> I suppose some are conversions and some reinterpretations.  What I
> should have said it that there are cases where cast reinterprets.

There are cases where the cast is defined to return a value that has the 
same bit pattern as its argument, to the extent the hardware can support 
it.  However, this is obviously limited to the values for which C 
actually defines the bit patterns of its values, namely the scalar 
integers.

Again, you're taking a special case and treating all the rest (which are 
a majority) as aberations.  For the most part, casts do *not* return the 
same bit pattern as the value.  For the most part
union {T1 x; T2 y;};
can be used to do transformations that
T2 y; T1 x = (T1) y;
does not. Indeed, the only bit patterns that don't change are when 
casting from signed to unsigned versions of the same underlying scalar 
type and back. Everything else must change, except perhaps pointers, 
depending on your architecture. (I've worked on machines where char* had 
more bits than long*, for example.)

(Funny that comp.lang.c isn't on this thread. ;-)

-- 
   Darren New / San Diego, CA, USA (PST)
     My Bath Fu is strong, as I have
     studied under the Showerin' Monks.



More information about the Python-list mailing list