[net.lang.c++] statics in state tables

nathan@orstcs.UUCP (nathan) (03/12/86)

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

rbm@sfsup.UUCP (R.B.Murray) (03/14/86)

> 
> 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


Actually, in release 1.0, the default storage class for globals is "extern",
just as in "C". I suspect you're using release E, which is obsolete.
	Cfront release E was released to universities (only)
for a nominal charge in early 1985.  This was a preliminary
version of cfront (and was advertised as such).
Users of release E ought to get 1.0, as the language has changed since then.
What follows is a list of these changes. (This list is also in the 1.0 release
notes.)

**NOTE: This list is ONLY relevant if you are at one of the
universities that got release E. The 1.0 release, and
the book, already reflect these changes:

1. The default storage class of globals is static, as in C;
2. You can't initialize references with pointers;
3. Undeclared functions are no longer implicitly declared according to the
	first use.  Instead, an undeclared function is treated as in good-old-C,
	i.e. all args are passed unchecked;
4. Static constructors and destructors can always be used (the +I flag is
	no longer needed);
5. The correct syntax for defining a member function uses "::"

	struct cls {
		void member();
	};

	void cls::member(){}
	//Used to be: void cls.member(){}

6. You can delete a vector of class objects with the syntax 
	delete [count] ptr;
  e.g.
	object* ptr;
	ptr = new object[20];
	delete [20] ptr;

7. Improved member initializations.
When a class object has members that are themselves class objects, 
arguments can now be passed to the constructors of those members.

class inner { 
	inner(int);
};

class outer {
	inner in;
	outer(float, int);
};

	//This constructor first calls 
	//inner::inner(i+1)

outer::outer(float f, int i) : in( i + 1 ) {
/* ... */
}

8. Many bug fixes.


Rob Murray
AT&T
Summit, NJ