Previous: Structs and unions, Up: The type section [Contents][Index]
When the compiler encounters a forward declaration of a struct, union, or enum,
it emits a type of kind CTF_K_FORWARD
. If it later encounters a non-
forward declaration of the same thing, it marks the forward as non-root-visible:
before link time, therefore, non-root-visible forwards indicate that a
non-forward is coming.
After link time, forwards are fused with their corresponding non-forwards by the
deduplicator where possible. They are kept if there is no non-forward
definition (maybe it’s not visible from any TU at all) or if multiple
conflicting structures with the same name might match it. Otherwise, all other
forwards are converted to structures, unions, or enums as appropriate, even
across TUs if only one structure could correspond to the forward (after all,
all types across all TUs land in the same dictionary unless they conflict,
so promoting forwards to their concrete type seems most helpful).
A forward has a rather strange representation: it is encoded with a
ctf_stype_t
but the ctt_type
is populated not with a type (if it’s
a forward, we don’t have an underlying type yet: if we did, we’d have promoted
it and this wouldn’t be a forward any more) but with the kind
of the
forward. This means that we can distinguish forwards to structs, enums and
unions reliably and ensure they land in the appropriate namespace even before
the actual struct, union or enum is found.