[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ProgSoc] Programming! Code!



On Thursday 19 October 2006 19:54, Roland Turner wrote:
> Has the Tortoise started breaking Achilles' record players yet?

No. (...and, yes.)

The Tortoise doesn't break Achilles's (sic) record players. The Tortoise 
breaks the Crab's record players...

> > Thus, bool not(bool x) and Boolean not(Boolean x) are semantically
> > identical.
>
> Egads, there are no non-null value types?

C# != Java.

ValueTypes are not reference types, and they are allocated without an 
object header on either the stack or (in an object on) the heap.

ValueType inherits from Object, but it is fundamentally different. A 
value type is not an 'object' (i.e. allocated an object id and managed 
by the GC) unless it is boxed.

ValueTypes implement copy-by-value semantics.

To declare a value type (derives from ValueType) in C# you declare 
a 'struct'. To declare a reference type (does not derive from 
ValueType) you declare a 'class'.

It is possible to pass pointers to ValueTypes in C# using the 'ref' 
and 'out' keywords. If you throw the 'unsafe' switch C# is basically 
C++ -- you can pass pointers to anything. There is no 'const' pointer 
passing in C#.

In order to facilitate the illusion that ValueType inherits from Object 
the CLR provides for 'boxing'. Boxing is automatic, unboxing is not.

Boxing occurs when a value type is stored in a reference type variable.

E.g. boxing occurs here:

 Object o = true; // <-- boxed

Boxing involves allocating a copy of a value inline in an 'object' on 
the heap and returning a reference to that object.

Boxing does not occur here:

 Boolean b = true;

No boxing occurs here:

 bool b1 = true;
 Boolean b2 = b1;

Unboxing occurs here:

 Object o = true;        // <-- boxed
 Boolean b = (Boolean)o; // <-- unboxed

Spec# refers to non-null reference types (the Null Object pattern is 
better, null references are stupid).

It is possible to represent 'null values' in a value type and to 
implement for those types TVL (three-valued logic). 

If you have any other questions feel free to ask... I know all about 
it. :)







-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.