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: More specifically ... and on closures Keywords: C style static initialization Message-ID: <131@mole-end.UUCP> Date: 23 Dec 88 20:42:01 GMT References: <421@aber-cs.UUCP> <127@mole-end.UUCP> <774@auspex.UUCP> <470@pyuxf.UUCP> <421@aber-cs.UUCP> Distribution: eunet,world Organization: mole-end--private system. admin: mole-end!newtnews Lines: 48 > >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