Debugging, statics.

Mark A Terribile mat at mole-end.UUCP
Tue Dec 20 13:58:12 AEST 1988


|     The ... moral is to not use block-scope static initialization, ... a
|     better one [is] to design utility programs [that are] serially reusable.
| 
| I beg to ... dig deeper into the problem. The moral is that by using statics
| ... you can only write single instance generators, and that this single
| instance is indeed not reusable if you dont' refresh it.
| ...
| Generators are not subroutines. In most algorithmic languages like C the easy
| way to write a generator (a coroutine) is to store its state in
| statics/globals. Then you can only have one instance of the generator.

True, but please allow me to point out that this problem is trivial in C++
(I know, this is a group about C) and that using a struct to represent the
state is exactly the *implementation* of the C++ idiom.  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.  Because there is no
automatic aggregate initialization, you end up resorting to statics.  I have
no good solution except to take the plunge UPWARD to C++.
-- 

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



More information about the Comp.lang.c mailing list