Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 1.79 KB

ii.16-defining-and-referencing-fields.md

File metadata and controls

38 lines (24 loc) · 1.79 KB

II.16 Defining and referencing fields

Fields are typed memory locations that store the data of a program. The CLI allows the declaration of both instance and static fields. While static fields are associated with a type, and are shared across all instances of that type, instance fields are associated with a particular instance of that type. Once instantiated, an instance has its own copy of each instance field. The CLI also supports global fields, which are fields declared outside of any type definition. Global fields shall be static.

A field is defined by the .field directive: (§II.22.15)

Field ::=
.field FieldDecl
FieldDecl ::=
[ '[' Int32 ']' ] FieldAttr* Type Id [ '=' FieldInit

The FieldDecl has the following parts:

  • An optional integer specifying the byte offset of the field within an instance (§II.10.7). If present, the type containing this field shall have the explicit layout attribute. An offset shall not be supplied for global or static fields.

  • Any number of field attributes (§II.16.2).

  • Type.

  • Name.

  • Optionally, either a FieldInit clause (§II.16.2) or a DataLabelII.5.4) clause.

Global fields shall have a data label associated with them. This specifies where, in the PE file, the data for that field is located. Static fields of a type can, but need not, be assigned a data label.

[Example:

.field private class [.module Counter.dll]Counter counter
.field public static initonly int32 pointCount
.field private int32 xOrigin
.field public static int32 count at D_0001B040

end example]