c# - If Int32 is just an alias for int, how can the Int32 class use an int? -


been browsing through .net source code of .net framework reference source, fun of it. , found don't understand.

there int32.cs file c# code int32 type. , somehow seems strange me. how c# compiler compile code int32 type?

public struct int32: icomparable, iformattable, iconvertible {     internal int m_value;      // ...  } 

but isn't illegal in c#? if int alias for int32, should fail compile error cs0523:

struct member 'struct2 field' of type 'struct1' causes cycle in struct layout.

is there magic in compiler, or off track?

isn't illegal in c#? if "int" alias "int32" should fail compile error cs0523. there magic in compiler?

yes; error deliberately suppressed in compiler. cycle checker skipped entirely if type in question built-in type.

normally sort of thing illegal:

struct s { s s; int i; } 

in case size of s undefined because whatever size of s is, must equal plus size of int. there no such size.

struct s { s s; } 

in case have no information deduce size of s.

struct int32 { int32 i; } 

but in case compiler knows ahead of time system.int32 4 bytes because special type.

incidentally, details of how c# compiler (and, matter, clr) determines when set of struct types cyclic extremely interesting. i'll try write blog article @ point.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -