Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Uncle Steve Newsgroups: comp.lang.c Subject: Re: Non-constant initializers Date: Sat, 14 May 2011 18:09:33 -0400 Organization: Friends of the Galactic Collective Lines: 50 Message-ID: <92f904404cb7d63-61def@gmail.com> References: <0ca8ca5b-e73e-418a-935f-0fcc17fdf404@q14g2000prh.googlegroups.com> <9322eedb3a632f5-29a98@gmail.com> <70b21f510c7390e-cc0de@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit Injection-Info: mx03.eternal-september.org; posting-host="UJ+SW6EYtZE9LcEeFRrivQ"; logging-data="3749"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18InriAogD2RLHUWCZOeQd7" User-Agent: nn 6.7.3 Content-Length: 2058 Cancel-Lock: sha1:HOGLkUqtcjxcOcqjl21O/bBBfFU= Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:3986 On Sat, May 14, 2011 at 05:45:49PM -0400, Eric Sosman wrote: > On 5/14/2011 3:25 PM, Uncle Steve wrote: > >On Sat, May 14, 2011 at 02:30:58PM -0500, Shao Miller wrote: > >>[...] > >>No answer to this one? If the very first thing main() does is to call > >>an init() which populates your globals' values, then that init() makes > >>for a nicely-readable section of code to gather these items into one > >>place. > > > >You're making this too easy. What could be cleaner than a variable > >declaration outside of main() which also initializes it to the value it > >should have before main() is called? [...] > > Since it's not C, it's infinitely UNclean in C terms. Also, > you'll find that languages permitting this sort of thing are all > festooned with great garlands of special rules about the order in > which these initializers get executed. Consider your hypothetical > file-scope function call, for example: Are stdin/out/err open and > ready for use when the function runs? What about the `FILE *foo;' > that you also fopen() at file-scope? Has the malloc() arena been > initialized yet? What about floating-point environment flags? And > so on, and so on. I just know I'm going to get into trouble continuing with this. Might I suggest that it wouldn't be too terrible if the C compiler had provisions for well-defined user initialization code, happening after all the libc initialization, etc.? I know it's not in the standard, but it would be kind of nice to have. > >>Well it's an opportunity to suggest that C functions do not return > >>arrays, as far as I know. If howmuchfoo() was a macro that expanded to > >>an initializer list, then I believe that'd be fine. > > > >It could do just about anything if it was a C function, couldn't it? > > C functions cannot return arrays, nor can they return array > initializers. Hmm. I'm not sure why you think that's important. Regards, Uncle Steve -- Should a professional politician be charged with molestation if he kisses babies while attending political rallies?