Debugging, statics.

Guy Harris guy at auspex.UUCP
Thu Dec 22 08:36:31 AEST 1988


>The difficulty in C is that you can't force an instance of a struct to
>be initialized when it is declared, especially if it is declared
>locally.

Err, umm, better make that "*only* if it declared locally".  There's no
particular problem with

	struct foo {
		int a;
		char *b;
		float c;
	} bar = {
		666,
		"Hello, sailor!",
		137.06
	};

if "bar" is "static" or "external".

>Because there is no automatic aggregate initialization,

Automatic initialization is often (always?) just syntactic sugar.  You
can do

	foo()
	{
		int a = 33;
		struct foo b = { 666, "Hello, sailor!", 137.06};

		...
	}

by doing

	foo()
	{
		int a = 33;
		struct foo b;

		b.a = 666;
		b.b = "Hello, sailor!";
		b.c = 137.06;

		...
	}

The problem here appears to be that C makes it inconvenient to have
non-automatic, private data that belongs to an *instance* of the
generator; there's only one copy of a "static", so you don't get one per
customer.  (C doesn't make it *impossible*, of course.)



More information about the Comp.lang.c mailing list