Thread View: comp.std.c++
4 messages
4 total messages
Started by MichaelFurman
Mon, 02 Oct 1995 16:14
Re: Static objects initialization before main()
Author: MichaelFurman
Date: Mon, 02 Oct 1995 16:14
Date: Mon, 02 Oct 1995 16:14
82 lines
4298 bytes
4298 bytes
In article <44j7pn$ca9@oznet07.ozemail.com.au>,
John Max Skaller <maxtal@suphys.physics.su.oz.au> wrote:
>engr@gssi.MV.COM (MichaelFurman) wrote:
>> Reading some answers in C++ newsgroups and ARM I found that feature that
>>I am using is not supported by C++ draft standard. I rely on fact that all
>>static class instances in the program will be initialized (by calling
>>appropriate constructors) before executing "main" function. I do not know
>>how to implement what I want (see below) without it.
>[]
>> If initialization can be "deferred to any point in time before the first
>>use a function or object defined in that translation unit" (as described in
>>ARM and I believe - I do not have it with me - in draft standard) - I can
>>not implement this strategy at all because in main part of software I do not
>>know which translation units - drivers - I have. It seams to me that I can
>>not avoid recompilation of some file and I have to change that file each
>>time I implement a new driver.
>
> Not true. You cannot implement PORTABLE code that way. You CAN
>rely on a particular compiler though.
Either I can rely on another language e. t. c.
Seriously, of cause, in my particular program I am relying on compiler(s)
I have and I do not think I will have a trouble in nearest future. But reason
of my post is not a solving my problem, but discussing features of C++.
> If you are implementing
>device drivers, this might not be so much of a problem.
It is not necessary device drivers - they may be modules of any expandable
system.
>
>>
>>My questions:
>>
>>1. What is a reason of allowing it to be deferred.
>
> Dynamic Link Libraries.
>
>>2. May be I just don't see how to implement it better, without relying on
>>this unsupported fact (actually all compilers I know do it before calling
main)
>.
>
> The correct way to implement it requires writing an initialisation
>module which DOES know what drivers are to be supplied. To avoid
>writing it out by hand all the time, write a program to generate
>this initialisation function from information obtained somehow
>from a specication file describing the available drivers.
The problem is that is no portable form of such specification file
(it may be only input data for linker or executable program file). And there
is no portable way to do something with this information. And it is
nothing with C++.
>
>>3. If not - may be it is possible to consider changing the standard.
>
> This topic has been discussed many times: the current situation
>is not entirely satisfactory. Unfortunately, any solution appears
>to require a language extension.
Yes, I understand it. But all we need - just to mark somehow definitions
of objects that has to be initialized before executing "main". May be some
existant language attribute can be used? Global scope? No - it would prevent
optimisation based on virtual memory. "Const"? Do anybody have an idea?
Regards,
Michael Furman
----------------------------------------------------------------------------
--------
Michael Furman, (603)893-1109
Geophysical Survey Systems, Inc. fax:(603)889-3984
13 Klein Drive - P.O. Box 97 engr@gssi.mv.com
North Salem, NH 03073-0097 71543.1334@compuserve.com
----------------------------------------------------------------------------
--------
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Static objects initialization before main()
Author: Pulkkinen Esa
Date: Tue, 03 Oct 1995 18:19
Date: Tue, 03 Oct 1995 18:19
34 lines
2111 bytes
2111 bytes
In article <199510021604.MAA10538@mv.mv.com>, MichaelFurman <engr@gssi.MV.COM> wrote: > >Yes, I understand it. But all we need - just to mark somehow definitions >of objects that has to be initialized before executing "main". May be some >existant language attribute can be used? Global scope? No - it would prevent >optimisation based on virtual memory. "Const"? Do anybody have an idea? > I once thought marking an object volatile would do the trick. Since as the DWP states ([dcl.type.cv]/7) volatile is meant to disallow a set of optimizations for the use of the object. When an object is volatile, the compiler shouldn't make any assumptions about when the object's value is changed. Thus, since the compiler can't know when the object's value is changed, it can't rely it being initialized when the first use of the object is made [basic.start.init]/1 (perhaps in an interrupt etc), except if it initializes the object before main(). Of course this applies only to volatile objects with static storage duration and user defined constructor. I understand this isn't perhaps what volatile is meant for (the DWP says it should work "as in C"), but it certainly fits with my view of how volatile should work. -- Esa Pulkkinen | C++ programmers do it virtually E-Mail: esap@cs.tut.fi | everywhere with a class, resulting WWW : http://www.cs.tut.fi/~esap/ | in multiple inheritance. --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Static objects initialization before main()
Author: Michael Furman
Date: Wed, 04 Oct 1995 16:07
Date: Wed, 04 Oct 1995 16:07
28 lines
1909 bytes
1909 bytes
In article <44rrsp$r59@peippo.cs.tut.fi>, esap@cs.tut.fi says... > >I once thought marking an object volatile would do the trick. >Since as the DWP states ([dcl.type.cv]/7) volatile is meant to disallow >a set of optimizations for the use of the object. When an object is >volatile, the compiler shouldn't make any assumptions about when >the object's value is changed. Thus, since the compiler >can't know when the object's value is changed, it can't rely it >being initialized when the first use of the object is made >[basic.start.init]/1 (perhaps in an interrupt etc), except if it >initializes the object before main(). Of course this applies only to >volatile objects with static storage duration and user defined >constructor. I certainly like that. Is it possible to consider this as a proposal for changing C++ standard? Michael Michael Furman, (603)893-1109 Geophysical Survey Systems, Inc. fax:(603)889-3984 13 Klein Drive - P.O. Box 97 engr@gssi.mv.com North Salem, NH 03073-0097 71543.1334@compuserve.com ----------------------------------------------------------------------------- --- [ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu. Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Re: Static objects initialization before main()
Author: John Max Skaller
Date: Fri, 06 Oct 1995 15:03
Date: Fri, 06 Oct 1995 15:03
103 lines
5071 bytes
5071 bytes
engr@gssi.MV.COM (MichaelFurman) wrote:
>In article <44j7pn$ca9@oznet07.ozemail.com.au>,
>John Max Skaller <maxtal@suphys.physics.su.oz.au> wrote:
>
>>engr@gssi.MV.COM (MichaelFurman) wrote:
>>It seams to me that I can
>>>not avoid recompilation of some file and I have to change that file each
>>>time I implement a new driver.
>>
>> Not true. You cannot implement PORTABLE code that way. You CAN
>>rely on a particular compiler though.
>
>Seriously, of cause, in my particular program I am relying on compiler(s)
>I have and I do not think I will have a trouble in nearest future. But reason
>of my post is not a solving my problem, but discussing features of C++.
Sure. I personally strongly supported providing proper
support for control of initialisation in C++. However the problems
involved are difficult and in the end the committee has decided
mainly to ensure the existing specification is clear without
extending the semantics. Probably, this is right at this stage,
there are too many alternatives.
In general, there's conly one way to control complex initialisation
in C++: manually. I think little is lost here, because initialisation
of devices is inherently complex, operating system and device
specific, and generally initialisation of multiple devices CANNOT
be done independently for each device. So integrated initialisation
code may need to be written anyhow.
Perhaps the best solution of this kind of problem is
a meta-solution -- a program which generates initialisation
code. One might write that in C++ to generate C++ code
and build in appropriate rules.
>> If you are implementing
>>device drivers, this might not be so much of a problem.
>
>It is not necessary device drivers - they may be modules of any expandable
>system.
Agreed. But device drivers are a good example.
>> The correct way to implement it requires writing an initialisation
>>module which DOES know what drivers are to be supplied. To avoid
>>writing it out by hand all the time, write a program to generate
>>this initialisation function from information obtained somehow
>>from a specication file describing the available drivers.
>
>The problem is that is no portable form of such specification file
>(it may be only input data for linker or executable program file). And there
>is no portable way to do something with this information. And it is
>nothing with C++.
The form of the specification file is as portable as YOU make
it: you are writing the program which reads it and generates
appropriate code.
>>>3. If not - may be it is possible to consider changing the standard.
>>
>> This topic has been discussed many times: the current situation
>>is not entirely satisfactory. Unfortunately, any solution appears
>>to require a language extension.
>
>Yes, I understand it. But all we need - just to mark somehow definitions
>of objects that has to be initialized before executing "main".
That is possible of course, but I doubt it is "all we need". :-)
>May be some
>existant language attribute can be used? Global scope? No - it would prevent
>optimisation based on virtual memory. "Const"? Do anybody have an idea?
I'd guess many existing compilers either:
a) do global initialisation before main anyhow for non-DLL code
b) provide pragmas (Borland does, for example)
c) allow you to write and link in your own startup code
I know this is not portable. The problem is that portability requires
corresponding constraints on architectures. Standards bodies generally
decide not to dictate such constraints unless there is virtual
unanimity in this kind of thing.
It may well be appropriate, for example, to have standardised
C++ extensions in the POSIX standard, rather than the C++ one
(since POSIX already constrains OS architectures)
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
AUSTRALIA email: skaller@maxtal.com.au
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads