Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: notesfiles Path: utzoo!watmath!clyde!cbosgd!hplabs!hp-pcd!orstcs!nathan From: nathan@orstcs.UUCP (nathan) Newsgroups: net.lang.c++ Subject: statics in state tables Message-ID: <34200006@orstcs.UUCP> Date: Wed, 12-Mar-86 00:50:00 EST Article-I.D.: orstcs.34200006 Posted: Wed Mar 12 00:50:00 1986 Date-Received: Fri, 14-Mar-86 07:04:20 EST Organization: Oregon State University - Corvallis, OR Lines: 26 Nf-ID: #N:orstcs:34200006:000:1131 Nf-From: orstcs!nathan Mar 11 21:50:00 1986 Forward-declaring static variables: The following has been a problem in C; I wonder if it is still a problem in C++. Suppose you want to initialize a state table with circular references, and want the table entries declared static. For example: struct entry { entry* next; int i; }; static entry e1 = { &e2, 0 }; static entry e2 = { &e1, 1 }; The first initialization will fail, as e2 hasn't been seen yet. We need to "forward" declare e2 without defining it. But how? Putting an "extern" on would prevent definition, but would conflict with the "static" later on (at least according to the ANSI C draft). Calling them static in the forward-declaration would define them too. Do we need a special-case here (e.g. static overrides earlier extern)? If so, the manual should say so -- otherwise implementors will make their own merry mess of it. By the way, it seems to me a significant difference from C that the default storage class for globals is "static" -- worth noting at least in Section r.15, "Differences from C". I only noticed it by accident. Nathan C. Myers hplabs!hp-pcd!orstcs!nathan nathan@oregon-state