Path: utzoo!utgpu!watmath!clyde!att!westmark!mole-end!mat From: mat@mole-end.UUCP (Mark A Terribile) Newsgroups: comp.lang.c Subject: Re: Debugging, statics. Summary: For Generators, Look To the ++ Keywords: C style static initialization Message-ID: <127@mole-end.UUCP> Date: 20 Dec 88 03:58:12 GMT References: <421@aber-cs.UUCP> Distribution: eunet,world Organization: mole-end--private system. admin: mole-end!newtnews Lines: 22 | 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