Format | Assembly Format | Description |
---|---|---|
7C <T> | ldflda field |
Push the address of field of object obj on the stack. |
…, obj → …, address
The ldflda
instruction pushes the address of a field of obj. obj is either an object, type O
, a managed pointer, type &
, or an unmanaged pointer, type native int
. The use of an unmanaged pointer is not allowed in verifiable code. The value returned by ldflda
is a managed pointer (type &
) unless obj is an unmanaged pointer, in which case it is an unmanaged pointer (type native int
).
field is a metadata token (a fieldref
or fielddef
; see Partition II) that shall refer to a field member. The field can be either an instance field (in which case obj shall not be null) or a static field.
System.FieldAccessException
is thrown if field is not accessible.
System.InvalidOperationException
is thrown if the obj is not within the application domain from which it is being accessed. The address of a field that is not inside the accessing application domain cannot be loaded.
System.MissingFieldException
is thrown if field is not found in the metadata. This is typically checked when CIL is converted to native code, not at runtime.
System.NullReferenceException
is thrown if obj is null and the field isn't static.
Correct CIL ensures that field is a valid fieldref
token and that the type of obj is compatible-with the Class of field.
For verifiable code, obj shall not be an unmanaged pointer.
The tracked type of obj shall have, or be a managed pointer to a type which has, a static or instance field.
For verifiable code, field cannot be init-only.
It is not verifiable to access an overlapped object reference field.
A field is accessible only if every field that overlaps it is also accessible.
Verification (§III.1.8) tracks the type of the value loaded onto the stack as a managed pointer to the verification type (§I.8.7) of field.
Using ldflda
to compute the address of a static, init-only field and then using the resulting pointer to modify that value outside the body of the class initializer might lead to unpredictable behavior.