Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.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 17:00:29 -0400 Organization: Friends of the Galactic Collective Lines: 47 Message-ID: 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="28001"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18LNBuuXH5d6fxeyLwRWiez" User-Agent: nn 6.7.3 Content-Length: 2003 Cancel-Lock: sha1:gxhNGfiXVdFX6ohN6p0xdRgTQXE= Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:3981 On Sat, May 14, 2011 at 01:05:30PM -0700, Keith Thompson wrote: > Uncle Steve writes: > > On Sat, May 14, 2011 at 02:30:58PM -0500, Shao Miller wrote: > >> On 5/14/2011 12:59 PM, Uncle Steve wrote: > >> >On Thu, May 12, 2011 at 06:53:02PM -0500, Shao Miller wrote: > [...] > >> >>- Could you employ and enjoy an init() function which would initialize > >> >>these objects, then make that the first call inside main()? > >> >> > >> > >> 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? I'm fully aware that I can > > assign a value to a variable any time I write code or macros to do it, > > but there are certain kinds of application parameters, for instance, > > which you may derive empirically, and assign once. I should think > > that most programmers know about these types of variables. > > The clarity or simplicity of the concept is not the issue. > > Yes, the ability to declare a variable outside main() with a > non-constant initializer (say, using a function call) can be > very useful. > > But the fact is, standard C doesn't support this feature. If you > need it, you can use a workaround (several have been offered here), > or you can use a non-standard compiler extension if it's available, > or you can use a different language. So my question is really answered. Likely, I'll end up calling some function from main() and merely initialize pointers to NULL in the global section. No big deal, and thank you all for the suggestions. Regards, Uncle Steve -- Should a professional politician be charged with molestation if he kisses babies while attending political rallies?