Closed mewmew closed 8 years ago
Note, if support for forward references is to be added, it will not rely on the implicit forward reference semantics of C89, but rather the semantics used by the C# compiler, which parses source files using two-pass parsing. The first pass will simply parse file scope (i.e. global) declarations but skip function bodies. The second pass parses the full function bodies, having the global scope of declarations available during its semantic analysis phase, as further outlined in outlined in [1].
Our intention is to implement support for forward references (but not implicit references as defined by C89) by iterating over the global declarations and adding them to the file scope, before doing semantic analysis of the function bodies. Initially, this will be done without skipping function bodies during parsing, and thus requires only a single-pass parser. A future version of the compiler may use a two-pass parser to reduce memory usage when compiling several larger translation units.
To the best of our knowledge, adding support for forward references should not invalidate any currently valid C programs, but rather introduce a superset of C for which source files may be written using forward references without ambiguity.
The semantic analysis is implemented with support for forward references, as discussed in this issue. Support for implicit references has been explicitly left out.
Consider adding support for forward references.
C89 and the first edition of C90 had support for implicit function declarations (support for which was removed in the second revision of implicit declarations), as indicated by the following extract from the C89 draft.
Furthermore, clang and gcc supports implicit forward declarations.
Contents of
g.c
: