Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #3855 > unrolled thread

Non-constant initializers

Started byFred the Freshwater Catfish <usenet.fred@bdtd.invalid>
First post2011-05-12 22:59 +0000
Last post2011-05-13 23:57 +0000
Articles 20 on this page of 94 — 22 participants

Back to article view | Back to comp.lang.c

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-12 22:59 +0000
    Re: Non-constant initializers Ian Collins <ian-news@hotmail.com> - 2011-05-13 11:07 +1200
      Re: Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-12 23:17 +0000
        Re: Non-constant initializers Ian Collins <ian-news@hotmail.com> - 2011-05-13 11:20 +1200
          Re: Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-12 23:30 +0000
            Re: Non-constant initializers Ian Collins <ian-news@hotmail.com> - 2011-05-13 11:34 +1200
              Re: Non-constant initializers Keith Thompson <kst-u@mib.org> - 2011-05-12 16:52 -0700
                Re: Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-14 00:13 +0000
                  Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-14 01:28 +0000
                    Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 13:52 -0400
                  Re: Non-constant initializers kym@kymhorsell.com - 2011-05-14 01:54 +0000
                    Re: Non-constant initializers Columbus sailed the ocean China Blue <chine.bleu@yahoo.com> - 2011-05-14 01:07 -0700
                      Re: Non-constant initializers kym@kymhorsell.com - 2011-05-14 09:22 +0000
                        Re: Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-14 17:14 +0000
              Re: Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-14 00:11 +0000
    Re: Non-constant initializers Shao Miller <sha0.miller@gmail.com> - 2011-05-12 18:08 -0500
      Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-12 19:22 -0400
        Re: Non-constant initializers Shao Miller <sha0.miller@gmail.com> - 2011-05-12 18:53 -0500
          Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 13:59 -0400
            Re: Non-constant initializers Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-14 14:19 -0400
              Re: Non-constant initializers Shao Miller <sha0.miller@gmail.com> - 2011-05-14 15:04 -0500
              Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 15:10 -0400
                Re: Non-constant initializers James Kuyper <jameskuyper@verizon.net> - 2011-05-14 16:01 -0400
                  Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 16:57 -0400
            Re: Non-constant initializers Shao Miller <sha0.miller@gmail.com> - 2011-05-14 14:30 -0500
              Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 15:25 -0400
                Re: Non-constant initializers Keith Thompson <kst-u@mib.org> - 2011-05-14 13:05 -0700
                  Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 17:00 -0400
                Re: Non-constant initializers Shao Miller <sha0.miller@gmail.com> - 2011-05-14 16:14 -0500
                  Re: Non-constant initializers Shao Miller <sha0.miller@gmail.com> - 2011-05-14 16:49 -0500
                  Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 18:21 -0400
                    Re: Non-constant initializers Shao Miller <sha0.miller@gmail.com> - 2011-05-14 21:26 -0500
                      Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-15 14:01 -0400
                Re: Non-constant initializers Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-14 17:45 -0400
                  Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-14 18:09 -0400
                    Re: Non-constant initializers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-15 04:01 +0100
                      Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-15 13:26 -0400
                        Re: Non-constant initializers Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-05-16 02:32 +0100
                Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-15 03:59 +0000
                  Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-16 04:49 -0400
                    Re: Non-constant initializers pete <pfiland@mindspring.com> - 2011-05-16 07:27 -0400
                      Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-16 09:24 -0400
                        Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-16 19:10 +0000
                          Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-16 21:23 -0400
                    Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-16 19:10 +0000
                      Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-16 21:16 -0400
                        Re: Non-constant initializers James Kuyper <jameskuyper@verizon.net> - 2011-05-16 21:37 -0400
                          Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-16 22:42 -0400
                        Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-17 02:40 +0000
                          Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-16 22:50 -0400
                            Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-17 04:14 +0000
                              Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-17 17:37 -0400
                                Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-17 22:22 +0000
                                  Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-17 18:33 -0400
                                    Re: Non-constant initializers Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-05-18 01:58 -0700
                                      Re: Non-constant initializers Uncle Steve <stevet810@gmail.com> - 2011-05-18 12:45 -0400
                                    Re: Non-constant initializers "io_x" <a@b.c.invalid> - 2011-05-18 19:30 +0200
                                      Re: Non-constant initializers Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-18 20:01 +0100
                                    Re: bug-free C code (was: Non-constant initializers) Seebs <usenet-nospam@seebs.net> - 2011-05-19 02:21 +0000
                                      Re: bug-free C code (was: Non-constant initializers) Keith Thompson <kst-u@mib.org> - 2011-05-18 20:00 -0700
                                        Re: bug-free C code (was: Non-constant initializers) Seebs <usenet-nospam@seebs.net> - 2011-05-19 03:14 +0000
                                          Re: bug-free C code (was: Non-constant initializers) Keith Thompson <kst-u@mib.org> - 2011-05-19 07:49 -0700
                                            Re: bug-free C code (was: Non-constant initializers) Seebs <usenet-nospam@seebs.net> - 2011-05-19 15:16 +0000
                                    Re: bug-free C code Ben Pfaff <blp@cs.stanford.edu> - 2011-05-18 20:02 -0700
                                      Re: bug-free C code Keith Thompson <kst-u@mib.org> - 2011-05-18 20:09 -0700
                                        Re: bug-free C code Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-18 23:24 -0400
                                          Re: bug-free C code Angel <angel+news@spamcop.net> - 2011-05-19 06:39 +0000
                                            Re: bug-free C code Keith Thompson <kst-u@mib.org> - 2011-05-19 08:05 -0700
                                              Re: bug-free C code Angel <angel+news@spamcop.net> - 2011-05-19 16:22 +0000
                                                Re: bug-free C code Keith Thompson <kst-u@mib.org> - 2011-05-19 11:36 -0700
                                                  Re: bug-free C code Ben Pfaff <blp@cs.stanford.edu> - 2011-05-19 12:21 -0700
                                                    Re: bug-free C code Keith Thompson <kst-u@mib.org> - 2011-05-19 13:12 -0700
                                                      Re: bug-free C code gazelle@shell.xmission.com (Kenny McCormack) - 2011-05-19 21:52 +0000
                                                        Re: bug-free C code Angel <angel+news@spamcop.net> - 2011-05-19 22:16 +0000
                                                          Re: bug-free C code Shao Miller <sha0.miller@gmail.com> - 2011-05-19 17:25 -0500
                                                          Re: bug-free C code Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:32 -0400
                                                  Re: bug-free C code gazelle@shell.xmission.com (Kenny McCormack) - 2011-05-19 21:51 +0000
                                                    Re: bug-free C code Kenneth Brody <kenbrody@spamcop.net> - 2011-05-20 13:30 -0400
                                    Re: bug-free C code "Joel C. Salomon" <joelcsalomon@gmail.com> - 2011-05-18 23:13 -0400
                                      Re: bug-free C code Dr Nick <3-nospam@temporary-address.org.uk> - 2011-05-19 08:23 +0100
        Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-13 00:15 +0000
        Re: Non-constant initializers "io_x" <a@b.c.invalid> - 2011-05-13 11:01 +0200
      Re: Non-constant initializers Columbus sailed the ocean China Blue <chine.bleu@yahoo.com> - 2011-05-12 16:30 -0700
    Re: Non-constant initializers Columbus sailed the ocean China Blue <chine.bleu@yahoo.com> - 2011-05-12 16:15 -0700
      Re: Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-12 23:28 +0000
    Re: Non-constant initializers Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-05-12 18:01 -0600
      Re: Non-constant initializers Keith Thompson <kst-u@mib.org> - 2011-05-12 18:15 -0700
        Re: Non-constant initializers Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-05-12 22:56 -0600
          Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-13 05:18 +0000
            Re: Non-constant initializers Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-05-13 09:10 -0600
              Re: Non-constant initializers Seebs <usenet-nospam@seebs.net> - 2011-05-13 20:56 +0000
        Re: Non-constant initializers Tim Rentsch <txr@alumni.caltech.edu> - 2011-05-18 23:47 -0700
          Re: Non-constant initializers Keith Thompson <kst-u@mib.org> - 2011-05-19 08:15 -0700
      Re: Non-constant initializers Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> - 2011-05-13 23:57 +0000

Page 1 of 5  [1] 2 3 4 5  Next page →


#3855 — Non-constant initializers

FromFred the Freshwater Catfish <usenet.fred@bdtd.invalid>
Date2011-05-12 22:59 +0000
SubjectNon-constant initializers
Message-ID<OgcdY5.Lcq.Cst0A@btdt.invalid>
Hey guys,

I've been writing some code that I would prefer to be maximally
portable.  As I have mostly used Linux, gcc is pretty much the only C
compiler I've ever used under UN*X.  I'd like to use non-constant
initializers for some global variables.  I'm pretty sure I can get it
to work the way I want under gcc, but what of other compilers?  The
gcc documentation in info format says that ISO C99 allows this, and so
I expect some compilers built in the 90's will support the feature,
but to what extent is this true?

What I mean to learn is the general prevalence of this C feature.  If
there's no support for certain well-known platforms (maybe SunOS or
OSF/1, whatever) I may consider a different solution to the original
problem, but I'd like to know what I'm getting in to before I start
trying to read the docs for every bloody C compiler that ever hit the
'net in the last twenty years.

Thanks if you can shed any light on this subject.



Fred the Freshwater Catfish

[toc] | [next] | [standalone]


#3858

FromIan Collins <ian-news@hotmail.com>
Date2011-05-13 11:07 +1200
Message-ID<9337gtFoqoU4@mid.individual.net>
In reply to#3855
On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
> Hey guys,
>
> I've been writing some code that I would prefer to be maximally
> portable.  As I have mostly used Linux, gcc is pretty much the only C
> compiler I've ever used under UN*X.  I'd like to use non-constant
> initializers for some global variables.  I'm pretty sure I can get it
> to work the way I want under gcc, but what of other compilers?  The
> gcc documentation in info format says that ISO C99 allows this, and so
> I expect some compilers built in the 90's will support the feature,
> but to what extent is this true?

How do you derive the initialiser values?

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#3861

FromFred the Freshwater Catfish <usenet.fred@bdtd.invalid>
Date2011-05-12 23:17 +0000
Message-ID<2u43Sw.GXK.PAfQI@btdt.invalid>
In reply to#3858
On Fri, May 13, 2011 at 11:07:09AM +1200, Ian Collins wrote:
> On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
> >Hey guys,
> >
> >I've been writing some code that I would prefer to be maximally
> >portable.  As I have mostly used Linux, gcc is pretty much the only C
> >compiler I've ever used under UN*X.  I'd like to use non-constant
> >initializers for some global variables.  I'm pretty sure I can get it
> >to work the way I want under gcc, but what of other compilers?  The
> >gcc documentation in info format says that ISO C99 allows this, and so
> >I expect some compilers built in the 90's will support the feature,
> >but to what extent is this true?
> 
> How do you derive the initialiser values?

It should end up being a function call most of the time.



Fred the Freshwater Catfish

[toc] | [prev] | [next] | [standalone]


#3864

FromIan Collins <ian-news@hotmail.com>
Date2011-05-13 11:20 +1200
Message-ID<93389uFoqoU5@mid.individual.net>
In reply to#3861
On 05/13/11 11:17 AM, Fred the Freshwater Catfish wrote:
> On Fri, May 13, 2011 at 11:07:09AM +1200, Ian Collins wrote:
>> On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
>>> Hey guys,
>>>
>>> I've been writing some code that I would prefer to be maximally
>>> portable.  As I have mostly used Linux, gcc is pretty much the only C
>>> compiler I've ever used under UN*X.  I'd like to use non-constant
>>> initializers for some global variables.  I'm pretty sure I can get it
>>> to work the way I want under gcc, but what of other compilers?  The
>>> gcc documentation in info format says that ISO C99 allows this, and so
>>> I expect some compilers built in the 90's will support the feature,
>>> but to what extent is this true?
>>
>> How do you derive the initialiser values?
>
> It should end up being a function call most of the time.

Then you either want C++, or a singleton fiddle as posted else-thread.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#3869

FromFred the Freshwater Catfish <usenet.fred@bdtd.invalid>
Date2011-05-12 23:30 +0000
Message-ID<PKQM7h.2nC.DM4ea@btdt.invalid>
In reply to#3864
On Fri, May 13, 2011 at 11:20:30AM +1200, Ian Collins wrote:
> On 05/13/11 11:17 AM, Fred the Freshwater Catfish wrote:
> >On Fri, May 13, 2011 at 11:07:09AM +1200, Ian Collins wrote:
> >>On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
> >>>Hey guys,
> >>>
> >>>I've been writing some code that I would prefer to be maximally
> >>>portable.  As I have mostly used Linux, gcc is pretty much the only C
> >>>compiler I've ever used under UN*X.  I'd like to use non-constant
> >>>initializers for some global variables.  I'm pretty sure I can get it
> >>>to work the way I want under gcc, but what of other compilers?  The
> >>>gcc documentation in info format says that ISO C99 allows this, and so
> >>>I expect some compilers built in the 90's will support the feature,
> >>>but to what extent is this true?
> >>
> >>How do you derive the initialiser values?
> >
> >It should end up being a function call most of the time.
> 
> Then you either want C++, or a singleton fiddle as posted else-thread.

Sorry, I'm not using C++.



Fred the Freshwater Catfish

[toc] | [prev] | [next] | [standalone]


#3870

FromIan Collins <ian-news@hotmail.com>
Date2011-05-13 11:34 +1200
Message-ID<93393vFoqoU6@mid.individual.net>
In reply to#3869
On 05/13/11 11:30 AM, Fred the Freshwater Catfish wrote:
> On Fri, May 13, 2011 at 11:20:30AM +1200, Ian Collins wrote:
>> On 05/13/11 11:17 AM, Fred the Freshwater Catfish wrote:
>>> On Fri, May 13, 2011 at 11:07:09AM +1200, Ian Collins wrote:
>>>> On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
>>>>> Hey guys,
>>>>>
>>>>> I've been writing some code that I would prefer to be maximally
>>>>> portable.  As I have mostly used Linux, gcc is pretty much the only C
>>>>> compiler I've ever used under UN*X.  I'd like to use non-constant
>>>>> initializers for some global variables.  I'm pretty sure I can get it
>>>>> to work the way I want under gcc, but what of other compilers?  The
>>>>> gcc documentation in info format says that ISO C99 allows this, and so
>>>>> I expect some compilers built in the 90's will support the feature,
>>>>> but to what extent is this true?
>>>>
>>>> How do you derive the initialiser values?
>>>
>>> It should end up being a function call most of the time.
>>
>> Then you either want C++, or a singleton fiddle as posted else-thread.
>
> Sorry, I'm not using C++.

But you require a C++ feature...

You could compile all but main() as C and compile the source file 
containing main() and your initialisers as C++.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#3874

FromKeith Thompson <kst-u@mib.org>
Date2011-05-12 16:52 -0700
Message-ID<lniptfiiic.fsf@nuthaus.mib.org>
In reply to#3870
Ian Collins <ian-news@hotmail.com> writes:
> On 05/13/11 11:30 AM, Fred the Freshwater Catfish wrote:
>> On Fri, May 13, 2011 at 11:20:30AM +1200, Ian Collins wrote:
>>> On 05/13/11 11:17 AM, Fred the Freshwater Catfish wrote:
>>>> On Fri, May 13, 2011 at 11:07:09AM +1200, Ian Collins wrote:
>>>>> On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
>>>>>> Hey guys,
>>>>>>
>>>>>> I've been writing some code that I would prefer to be maximally
>>>>>> portable.  As I have mostly used Linux, gcc is pretty much the only C
>>>>>> compiler I've ever used under UN*X.  I'd like to use non-constant
>>>>>> initializers for some global variables.  I'm pretty sure I can get it
>>>>>> to work the way I want under gcc, but what of other compilers?  The
>>>>>> gcc documentation in info format says that ISO C99 allows this, and so
>>>>>> I expect some compilers built in the 90's will support the feature,
>>>>>> but to what extent is this true?
>>>>>
>>>>> How do you derive the initialiser values?
>>>>
>>>> It should end up being a function call most of the time.
>>>
>>> Then you either want C++, or a singleton fiddle as posted else-thread.
>>
>> Sorry, I'm not using C++.
>
> But you require a C++ feature...
>
> You could compile all but main() as C and compile the source file 
> containing main() and your initialisers as C++.

Or, rather than using a non-constant initializer, you can call a routine
from main() that initialize the objects.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Nokia
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#3924

FromFred the Freshwater Catfish <usenet.fred@bdtd.invalid>
Date2011-05-14 00:13 +0000
Message-ID<yemBS9.FUV.7wkYM@btdt.invalid>
In reply to#3874
On Thu, May 12, 2011 at 04:52:43PM -0700, Keith Thompson wrote:
> Ian Collins <ian-news@hotmail.com> writes:
> > On 05/13/11 11:30 AM, Fred the Freshwater Catfish wrote:
> >> On Fri, May 13, 2011 at 11:20:30AM +1200, Ian Collins wrote:
> >>> On 05/13/11 11:17 AM, Fred the Freshwater Catfish wrote:
> >>>> On Fri, May 13, 2011 at 11:07:09AM +1200, Ian Collins wrote:
> >>>>> On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
> >>>>>> Hey guys,
> >>>>>>
> >>>>>> I've been writing some code that I would prefer to be maximally
> >>>>>> portable.  As I have mostly used Linux, gcc is pretty much the only C
> >>>>>> compiler I've ever used under UN*X.  I'd like to use non-constant
> >>>>>> initializers for some global variables.  I'm pretty sure I can get it
> >>>>>> to work the way I want under gcc, but what of other compilers?  The
> >>>>>> gcc documentation in info format says that ISO C99 allows this, and so
> >>>>>> I expect some compilers built in the 90's will support the feature,
> >>>>>> but to what extent is this true?
> >>>>>
> >>>>> How do you derive the initialiser values?
> >>>>
> >>>> It should end up being a function call most of the time.
> >>>
> >>> Then you either want C++, or a singleton fiddle as posted else-thread.
> >>
> >> Sorry, I'm not using C++.
> >
> > But you require a C++ feature...
> >
> > You could compile all but main() as C and compile the source file 
> > containing main() and your initialisers as C++.
> 
> Or, rather than using a non-constant initializer, you can call a routine
> from main() that initialize the objects.

That's a pretty good idea, but I was looking for something convenient
to set-up global-scope variables in a library.  No big deal, but I
thought I could be clever about it.



Fred the Freshwater Catfish

[toc] | [prev] | [next] | [standalone]


#3926

FromSeebs <usenet-nospam@seebs.net>
Date2011-05-14 01:28 +0000
Message-ID<slrnisrjkb.mg6.usenet-nospam@guild.seebs.net>
In reply to#3924
On 2011-05-14, Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> wrote:
> That's a pretty good idea, but I was looking for something convenient
> to set-up global-scope variables in a library.  No big deal, but I
> thought I could be clever about it.

Idle side question:

There's this one guy who rotates names occasionally and asks questions
that feel a lot like this, always using an invalid address, and who rotates
user agents every time he does...  And who hasn't posted for a bit.  Anyone
getting that sort of vibe from this?  (Previous names include, but are not
limited to, "Uno" and "Phred Phungus".)

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#3960

FromUncle Steve <stevet810@gmail.com>
Date2011-05-14 13:52 -0400
Message-ID<4ae3a420e6569d9-e1a57@gmail.com>
In reply to#3926
On Sat, May 14, 2011 at 01:28:21AM +0000, Seebs wrote:
> On 2011-05-14, Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> wrote:
> > That's a pretty good idea, but I was looking for something convenient
> > to set-up global-scope variables in a library.  No big deal, but I
> > thought I could be clever about it.
> 
> Idle side question:
> 
> There's this one guy who rotates names occasionally and asks questions
> that feel a lot like this, always using an invalid address, and who rotates
> user agents every time he does...  And who hasn't posted for a bit.  Anyone
> getting that sort of vibe from this?  (Previous names include, but are not
> limited to, "Uno" and "Phred Phungus".)

I could say I'm not related to whomever you're referring to, but would
anyone care?

To my recollection, I've posted to comp.arch and comp.lang.c on a mere
handful of occasions in the ten or so years I've been posting to
Usenet.  What may be happening here is you may be annoyed at my parody
of code examples in netnews messages.



Regards,

Uncle Steve

-- 
Should a professional politician be charged with molestation if he
kisses babies while attending political rallies?

[toc] | [prev] | [next] | [standalone]


#3927

Fromkym@kymhorsell.com
Date2011-05-14 01:54 +0000
Message-ID<4dcde0cd$0$24911$afc38c87@news.optusnet.com.au>
In reply to#3924
In comp.arch Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> wrote:
...
> That's a pretty good idea, but I was looking for something convenient
> to set-up global-scope variables in a library.  No big deal, but I
> thought I could be clever about it.

On some platforms its the linker that's responsible for once-only
runtime initialisations. If you name a routine in a special way,
or make sure it's in a code segment with a special name, the linker
sets up code to ensure the code gets called before main(). No need
for static "has it been done yet" variables or explicit calls.

This is how gnu C++ compilers typically arrange for global initialisations.

Unlike the idea of calling C++ from C (which usually won't work), just
hanging off this hook generally does work -- if you can find the documentation.

-- 
If there was no warming or cooling trend, then the chance of 2007
being tied with 1998 [130 year record!] would be quite high.
  -- No Pressure <no.pressure.at.all@gmail.com>, 11 Dec 2010 05:20:39 -0800

[toc] | [prev] | [next] | [standalone]


#3933

FromColumbus sailed the ocean China Blue <chine.bleu@yahoo.com>
Date2011-05-14 01:07 -0700
Message-ID<chine.bleu-5E3613.01071714052011@reserved-multicast-range-not-delegated.example.com>
In reply to#3927
In article <4dcde0cd$0$24911$afc38c87@news.optusnet.com.au>, kym@kymhorsell.com 
wrote:

> In comp.arch Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> wrote:
> ...
> > That's a pretty good idea, but I was looking for something convenient
> > to set-up global-scope variables in a library.  No big deal, but I
> > thought I could be clever about it.
> 
> On some platforms its the linker that's responsible for once-only
> runtime initialisations. If you name a routine in a special way,
> or make sure it's in a code segment with a special name, the linker
> sets up code to ensure the code gets called before main(). No need
> for static "has it been done yet" variables or explicit calls.
> 
> This is how gnu C++ compilers typically arrange for global initialisations.
> 
> Unlike the idea of calling C++ from C (which usually won't work), just
> hanging off this hook generally does work -- if you can find the 
> documentation.

Unfortunately this solution is not guarenteed to be available on all platforms.

-- 
Damn the living - It's a lovely life.           I'm whoever you want me to be.
Silver silverware - Where is the love?       At least I can stay in character.
Oval swimming pool - Where is the love?    Annoying Usenet one post at a time.
Damn the living - It's a lovely life.                              In 1492....

[toc] | [prev] | [next] | [standalone]


#3937

Fromkym@kymhorsell.com
Date2011-05-14 09:22 +0000
Message-ID<4dce49d3$0$13390$afc38c87@news.optusnet.com.au>
In reply to#3933
In comp.arch Columbus sailed the ocean China Blue <chine.bleu@yahoo.com> wrote:
> In article <4dcde0cd$0$24911$afc38c87@news.optusnet.com.au>, kym@kymhorsell.com 
> wrote:
>> In comp.arch Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> wrote:
>> ...
>> > That's a pretty good idea, but I was looking for something convenient
>> > to set-up global-scope variables in a library.  No big deal, but I
>> > thought I could be clever about it.
>> On some platforms its the linker that's responsible for once-only
>> runtime initialisations. If you name a routine in a special way,
>> or make sure it's in a code segment with a special name, the linker
>> sets up code to ensure the code gets called before main(). No need
>> for static "has it been done yet" variables or explicit calls.
>> This is how gnu C++ compilers typically arrange for global initialisations.
>> Unlike the idea of calling C++ from C (which usually won't work), just
>> hanging off this hook generally does work -- if you can find the 
>> documentation.
> Unfortunately this solution is not guarenteed to be available on all platforms.

That's the agreed meaning of "on some platforms", yes.

---
Scientists are always changing their story and as a Conservative, I
have no tolerance for ambiguity.  It proves that all science is lies 
and the only thing we can trust is right wing rhetoric.
  -- BONZO@27-32-240-172 [86 nyms and counting], 14 Jan 2011 14:46 +1100

CORRECTION: True science, (remember that?) can be trusted, but this "science" 
is ALL LIES!
  -- BONZO@27-32-240-172 [86 nyms and counting], 19 Feb 2011 14:46 +1100

[toc] | [prev] | [next] | [standalone]


#3959

FromFred the Freshwater Catfish <usenet.fred@bdtd.invalid>
Date2011-05-14 17:14 +0000
Message-ID<s0IQvN.Gi2.VZav4@btdt.invalid>
In reply to#3937
On Sat, May 14, 2011 at 09:22:27AM +0000, kym@kymhorsell.com wrote:
> In comp.arch Columbus sailed the ocean China Blue <chine.bleu@yahoo.com> wrote:
> > In article <4dcde0cd$0$24911$afc38c87@news.optusnet.com.au>, kym@kymhorsell.com 
> > wrote:
> >> In comp.arch Fred the Freshwater Catfish <usenet.fred@bdtd.invalid> wrote:
> >> ...
> >> > That's a pretty good idea, but I was looking for something convenient
> >> > to set-up global-scope variables in a library.  No big deal, but I
> >> > thought I could be clever about it.
> >> On some platforms its the linker that's responsible for once-only
> >> runtime initialisations. If you name a routine in a special way,
> >> or make sure it's in a code segment with a special name, the linker
> >> sets up code to ensure the code gets called before main(). No need
> >> for static "has it been done yet" variables or explicit calls.
> >> This is how gnu C++ compilers typically arrange for global initialisations.
> >> Unlike the idea of calling C++ from C (which usually won't work), just
> >> hanging off this hook generally does work -- if you can find the 
> >> documentation.
> > Unfortunately this solution is not guaranteed to be available on all platforms.
> 
> That's the agreed meaning of "on some platforms", yes.


Yeah.  I know gcc supports constructor and destructor function
attributes, with some sort of "priority" ranking, but I haven't fooled
with it enough to make it work.  I don't know how other compilers fare
in this respect, but it seems like the kind feature that gets
implemented differently by each compiler.  I might end up using
zero-length arrays in structure definitions if I find it's popular
enough, but I'm really trying not to make my application require weird
stuff just to compile, or in fact to tie my application to gcc.



Fred the Freshwater Catfish

[toc] | [prev] | [next] | [standalone]


#3923

FromFred the Freshwater Catfish <usenet.fred@bdtd.invalid>
Date2011-05-14 00:11 +0000
Message-ID<VE0BgN.NVa.keJdC@btdt.invalid>
In reply to#3870
On Fri, May 13, 2011 at 11:34:23AM +1200, Ian Collins wrote:
> On 05/13/11 11:30 AM, Fred the Freshwater Catfish wrote:
> >On Fri, May 13, 2011 at 11:20:30AM +1200, Ian Collins wrote:
> >>On 05/13/11 11:17 AM, Fred the Freshwater Catfish wrote:
> >>>On Fri, May 13, 2011 at 11:07:09AM +1200, Ian Collins wrote:
> >>>>On 05/13/11 10:59 AM, Fred the Freshwater Catfish wrote:
> >>>>>Hey guys,
> >>>>>
> >>>>>I've been writing some code that I would prefer to be maximally
> >>>>>portable.  As I have mostly used Linux, gcc is pretty much the only C
> >>>>>compiler I've ever used under UN*X.  I'd like to use non-constant
> >>>>>initializers for some global variables.  I'm pretty sure I can get it
> >>>>>to work the way I want under gcc, but what of other compilers?  The
> >>>>>gcc documentation in info format says that ISO C99 allows this, and so
> >>>>>I expect some compilers built in the 90's will support the feature,
> >>>>>but to what extent is this true?
> >>>>
> >>>>How do you derive the initialiser values?
> >>>
> >>>It should end up being a function call most of the time.
> >>
> >>Then you either want C++, or a singleton fiddle as posted else-thread.
> >
> >Sorry, I'm not using C++.
> 
> But you require a C++ feature...
> 
> You could compile all but main() as C and compile the source file 
> containing main() and your initialisers as C++.

I guess, but then my code would be tainted by C++.  I'd rather avoid
requiring C++ in the build toolchain to compile the software.


Fred the Freshwater Catfish

[toc] | [prev] | [next] | [standalone]


#3859

FromShao Miller <sha0.miller@gmail.com>
Date2011-05-12 18:08 -0500
Message-ID<iqhpa0$n31$1@dont-email.me>
In reply to#3855
On 5/12/2011 5:59 PM, Fred the Freshwater Catfish wrote:
> ...I'd like to use non-constant
> initializers for some global variables.  I'm pretty sure I can get it
> to work the way I want under gcc, but what of other compilers?  The
> gcc documentation in info format says that ISO C99 allows this, and so
> I expect some compilers built in the 90's will support the feature,
> but to what extent is this true?

Could you please share an example of what kind of non-constant you'd be 
inclined to initialize a static-duration, file-scoped object with?  Are 
you talking about using a function's return value?  Are you talking 
about using the address of something whose address you don't know at 
some point in time?

[toc] | [prev] | [next] | [standalone]


#3865

FromUncle Steve <stevet810@gmail.com>
Date2011-05-12 19:22 -0400
Message-ID<e68b19561ee2543-31bc7@gmail.com>
In reply to#3859
On Thu, May 12, 2011 at 06:08:46PM -0500, Shao Miller wrote:
> On 5/12/2011 5:59 PM, Fred the Freshwater Catfish wrote:
> >...I'd like to use non-constant
> >initializers for some global variables.  I'm pretty sure I can get it
> >to work the way I want under gcc, but what of other compilers?  The
> >gcc documentation in info format says that ISO C99 allows this, and so
> >I expect some compilers built in the 90's will support the feature,
> >but to what extent is this true?
> 
> Could you please share an example of what kind of non-constant you'd be 
> inclined to initialize a static-duration, file-scoped object with?  Are 
> you talking about using a function's return value?  Are you talking 
> about using the address of something whose address you don't know at 
> some point in time?

Essentially, I'm looking to seed a few critical global variables with
run-time computed values.  Obviously, this will be the product of a
function call.  I would like to declare:

int foops[] = howmuchfoo(void);

and have everything work as I expect.  Pie in the sky for non-recent
UN*Xes?



Regards,

Uncle Steve

-- 
Should a professional politician be charged with molestation if he
kisses babies while attending political rallies?

[toc] | [prev] | [next] | [standalone]


#3873

FromShao Miller <sha0.miller@gmail.com>
Date2011-05-12 18:53 -0500
Message-ID<iqhrt1$v8n$1@dont-email.me>
In reply to#3865
On 5/12/2011 6:22 PM, Uncle Steve wrote:
> On Thu, May 12, 2011 at 06:08:46PM -0500, Shao Miller wrote:
>> On 5/12/2011 5:59 PM, Fred the Freshwater Catfish wrote:
>>> ...I'd like to use non-constant
>>> initializers for some global variables.  I'm pretty sure I can get it
>>> to work the way I want under gcc, but what of other compilers?  The
>>> gcc documentation in info format says that ISO C99 allows this, and so
>>> I expect some compilers built in the 90's will support the feature,
>>> but to what extent is this true?
>>
>> Could you please share an example of what kind of non-constant you'd be
>> inclined to initialize a static-duration, file-scoped object with?  Are
>> you talking about using a function's return value?  Are you talking
>> about using the address of something whose address you don't know at
>> some point in time?
>
> Essentially,

Are you the same person as "Fred the Freshwater Catfish"?  Or are you 
another person who also wishes to accomplish this type of thing?

> I'm looking to seed a few critical global variables with
> run-time computed values.  Obviously, this will be the product of a
> function call.  I would like to declare:
>
> int foops[] = howmuchfoo(void);
>
> and have everything work as I expect...

Some more questions:

- When do you wish this initialization to occur?  Prior to main()?

- Could you employ and enjoy an init() function which would initialize 
these objects, then make that the first call inside main()?

- In your code example, is howmuchfoo() supposed to be returning an 
array of 'int' or a single 'int'?

- Is your request a matter of being able to read, in your code, what 
will be computed for an object in the immediate vicinity of the object, 
rather than in another place (such as an init() function)?

- Would you be willing to use macros to accomplish this?

[toc] | [prev] | [next] | [standalone]


#3961

FromUncle Steve <stevet810@gmail.com>
Date2011-05-14 13:59 -0400
Message-ID<9322eedb3a632f5-29a98@gmail.com>
In reply to#3873
On Thu, May 12, 2011 at 06:53:02PM -0500, Shao Miller wrote:
> On 5/12/2011 6:22 PM, Uncle Steve wrote:
> >On Thu, May 12, 2011 at 06:08:46PM -0500, Shao Miller wrote:
> >>On 5/12/2011 5:59 PM, Fred the Freshwater Catfish wrote:
> >>>...I'd like to use non-constant
> >>>initializers for some global variables.  I'm pretty sure I can get it
> >>>to work the way I want under gcc, but what of other compilers?  The
> >>>gcc documentation in info format says that ISO C99 allows this, and so
> >>>I expect some compilers built in the 90's will support the feature,
> >>>but to what extent is this true?
> >>
> >>Could you please share an example of what kind of non-constant you'd be
> >>inclined to initialize a static-duration, file-scoped object with?  Are
> >>you talking about using a function's return value?  Are you talking
> >>about using the address of something whose address you don't know at
> >>some point in time?
> >
> >Essentially,
> 
> Are you the same person as "Fred the Freshwater Catfish"?  Or are you 
> another person who also wishes to accomplish this type of thing?

Apparently I've been caught out.  Now my stalkers will know that I
secretly lurk in c.l.c. occasionally.
 
> >I'm looking to seed a few critical global variables with
> >run-time computed values.  Obviously, this will be the product of a
> >function call.  I would like to declare:
> >
> >int foops[] = howmuchfoo(void);
> >
> >and have everything work as I expect...
> 
> Some more questions:
> 
> - When do you wish this initialization to occur?  Prior to main()?

In a perfect world.
 
> - Could you employ and enjoy an init() function which would initialize 
> these objects, then make that the first call inside main()?
> 
> - In your code example, is howmuchfoo() supposed to be returning an 
> array of 'int' or a single 'int'?

I don't see how that's relevant to the question.
 
> - Is your request a matter of being able to read, in your code, what 
> will be computed for an object in the immediate vicinity of the object, 
> rather than in another place (such as an init() function)?

That all depends on what kind of data the variables are going to hold.
One time, I might want to save/restore window size and positioning,
and in another place, the volume setting of application sounds.  It is
impossible to say, a priori, what variables will be used/set where, at
least at this stage of the design process.  
 
> - Would you be willing to use macros to accomplish this?

I'll think about it.



Regards,

Uncle Steve

-- 
Should a professional politician be charged with molestation if he
kisses babies while attending political rallies?

[toc] | [prev] | [next] | [standalone]


#3966

FromEric Sosman <esosman@ieee-dot-org.invalid>
Date2011-05-14 14:19 -0400
Message-ID<iqmh5c$faj$1@dont-email.me>
In reply to#3961
On 5/14/2011 1:59 PM, Uncle Steve wrote:
> On Thu, May 12, 2011 at 06:53:02PM -0500, Shao Miller wrote:
>> On 5/12/2011 6:22 PM, Uncle Steve wrote:
>>> [...] I would like to declare:
>>>
>>> int foops[] = howmuchfoo(void);
>>>
>>> and have everything work as I expect...
>>  [...]
>>
>> - In your code example, is howmuchfoo() supposed to be returning an
>> array of 'int' or a single 'int'?
>
> I don't see how that's relevant to the question.

     The point is that the one-line fragment you posted is not
valid C, not if `howmuchfoo(void)' is any kind of function at all.
(If `howmuchfoo' is a function-like macro, it can of course expand
at compile-time into pretty much anything.)  But if it's a function
call, the fragment is meaningless regardless of what scope it appears
in -- which means that by exhibiting it you have conveyed no meaning
to anyone.  It is as if you had offered `int foops[] = !<petunia/>;'
and expected people to understand you.  If you want to be understood,
you'll have to explain yourself more clearly.

     Something that strikes me as odd is that you(?) started this
thread with the statement that you(?) sought a "maximally portable"
solution.  Why, then, all this haring off after blatantly non-
portable approaches?  Lost sight of the objective, or just trolling?

-- 
Eric Sosman
esosman@ieee-dot-org.invalid

[toc] | [prev] | [next] | [standalone]


Page 1 of 5  [1] 2 3 4 5  Next page →

Back to top | Article view | comp.lang.c


csiph-web