chris dollin
unread,Dec 25, 2012, 5:07:40 AM12/25/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Dan Kortschak, Kyle Lemons, Patrick Mylund Nielsen, Sean Russell, golang-nuts, Boris Solovyov
On 25 December 2012 09:56, Dan Kortschak wrote:
>What is the order of package-level variable initialisation? It does not appear to be specified, e.g.
http://play.golang.org/p/08Fa0PgVcC
http://golang.org/ref/spec#Program_execution
...
Within a package, package-level variables are initialized, and
constant values are determined, in data-dependent order: if the
initializer of A depends on the value of B, A will be set after B. It
is an error if such dependencies form a cycle. Dependency analysis is
done lexically: A depends on B if the value of A contains a mention of
B, contains a value whose initializer mentions B, or mentions a
function that mentions B, recursively. If two items are not
interdependent, they will be initialized in the order they appear in
the source. Since the dependency analysis is done per package, it can
produce unspecified results if A's initializer calls a function
defined in another package that refers to B.
(etc)
Chris
--
Chris "allusive" Dollin