Core vs Library

Walter Bright newshound1 at digitalmars.com
Mon Apr 14 14:23:46 PDT 2008


Jarrett Billingsley wrote:
> It's not that the C# compiler knows what an int is, it's how the .net 
> runtime represents them.  As far as the C# type system is concerned, 'int' 
> and 'System.Int32' are one and the same.  If you could do "typeof(5)" in C# 
> it'd yield System.Int32.  System.Int32 is a value type, one of the builtin 
> types in the .net runtime.  Being a value type, it is allocated on the 
> stack, passed by copy, all the things you'd expect.
> 
> When a .net high-level language compiler (like the C# compiler) emits code, 
> it's emitting CLR, not x86.  If it emits a "div" instruction with two values 
> of type System.Int32 as its parameters, the JIT compiler then has the 
> opportunity to optimize that down to a single x86 "idiv" instruction rather 
> than making a subroutine call.  However, System.Int32s, being object types, 
> can still participate in object-like behavior - they can have methods and 
> such.

The CLR has a special 'int32' data type. See the spec for it:
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-335.pdf
section 8.2.2


> Remember that codegen in .net languages is a 2-step process, and as such, 
> the high-level language compiler is not really the one that has to deal with 
> low-level representation, even of basic types like int.

It still recognizes it as a special, core type.

What is happening is that C# does automatic boxing/unboxing of value 
types. See 8.2.4.



More information about the Digitalmars-d mailing list