Debugging, statics.

Mark A Terribile mat at mole-end.UUCP
Sat Dec 24 06:42:01 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".  [e.g.]
 
> 	struct foo {
> 		int a;
> 		char *b;
> 		float c;
> 	} bar = { ...

I should have written more carefully.

There is no way to declare a struct template such that EVERY INSTANCE of
that struct will be initialized AS SPECIFIED IN THE DECLARATION.

> >Because there is no automatic aggregate initialization,

> Automatic initialization is often (always?) just syntactic sugar.  You
> can do [a sequence of assignments].

True.  So are compound statements.  (You can always use gotos).  A datum
with an initializer tends to read somewhat differently than a datum
initialized by assignments to multitudes of sub-data.

On a different aspect of the topic,

>> ... using statics ... you can only write single instance generators, and
>> ... this single instance is indeed not reusable if you don't refresh it.
 ...
>> The real solution would be to have the state of the generator in a struct,
 ...
>... this [is] what LISP programmers know as a 'function closure', or `closure`
>for short:  an object that consists of a procedure, plus an associated
>execution environment ...  Unfortunately, LISP (and its relatives) is the
>only language I know of that supports explicitly the notion of a closure ...

Actually, your description of a closure could easily be applied to a C++ class.

> ... It is possible to provide such a mechanism in C ... for a specific ...
>case -- in order to provide a general-purpose function closure mechanism for
>C, you'd have to monkey ... with either the [OS] or the run-time environment.

C++ requires neither.
-- 

(This man's opinions are his own.)
>From mole-end				Mark Terribile



More information about the Comp.lang.c mailing list