From: Robert Griesemer Date: Tue, 6 May 2008 17:29:17 +0000 (-0700) Subject: Introduced forward declaration of types per discussion with ken. X-Git-Tag: weekly.2009-11-06~3783 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d222c65477e0c3215a8902eecfb3530687325cd8;p=gostls13.git Introduced forward declaration of types per discussion with ken. A forward-declared (or not yet fully defined) type must be used to construct (mutually) recursive type declarations. This simplifies the compiler and resolves the issue at which scope the forward- declared type is to be declared. SVN=117770 --- diff --git a/doc/go_lang.txt b/doc/go_lang.txt index 7fc7c27ffb..36cb941cf9 100644 --- a/doc/go_lang.txt +++ b/doc/go_lang.txt @@ -1,6 +1,6 @@ The Go Programming Language ---- -(April 29, 2008) +(May 5, 2008) This document is an informal specification/proposal for a new systems programming language. @@ -678,19 +678,26 @@ Pointer types are similar to those in C. PointerType = "*" Type. -We do not allow pointer arithmetic of any kind. +Pointer arithmetic of any kind is not permitted. *int *map[string] *chan -It is legal to write a pointer type (only) such as *T or **T even if T -is not yet defined as a type name. This allows the construction of -mutually recursive data types such as structs: +It is legal to write a pointer type (only) such as *T even if T is +an incomplete type (i.e., either not yet fully defined or forward +declared). This allows the construction of recursive types such as: - type S1 struct { s2 *S2 } // S2 is not yet declared - type S2 struct { s1 *S1 } + type S struct { s *S } -By the end of the package source, such types must be fully declared. +Together with a type forward declaration, mutually recursive types +can be constructed such as: + + type S2 // forward declaration of S2 + type S1 struct { s2 *S2 } + type S2 struct { s1 *S1 } + +By the end of the package source, all forward-declared types must be +fully declared if they are used. There are no pointer literals. @@ -976,13 +983,17 @@ A constant declaration gives a name to the value of a constant expression. Type declarations ---- -A type declaration introduces a name as a shorthand for a type. +A type declaration introduces a name as a shorthand for a type. Providing only +a name without a type serves as a forward declaration: The name is declared and +given an incomplete type. Incomplete types can be used together (and only) with +pointer types. TypeDecl = "type" ( TypeSpec | "(" TypeSpecList [ ";" ] ")" ). - TypeSpec = identifier Type . + TypeSpec = identifier [ Type ] . TypeSpecList = TypeSpec { ";" TypeSpec }. + type List // foward declaration type IntArray [16] int type ( Point struct { x, y float };