Topic: Problems with current 'main' (was: C++ Embraces Procedural Programming Over OO Programming)


Author: tasjaevan@gmail.com
Date: Wed, 22 Nov 2006 10:42:09 CST
Raw View

On Nov 22, 12:26 am, rdnewsNOSPAM2...@sbcglobal.net ("Tony") wrote:
> ""Alf P. Steinbach"" <a...@start.no> wrote in messagenews:4sflo4Fvec3aU1@mid.individual.net...
>
> > Problems: (A) having 'main' singled out as "the" startup function forces a
> > 'main'-centered design, especially with respect to dynamic initialization
> > of statics, where only those appearing in 'main's translation unit are
> > guaranteed to occur before 'main' is entered,Only POD's I believe. Class objects are another story (?).
>

No. File-scope POD objects do not have dynamic initialisation.

File-scope user-defined objects requiring dynamic initialisation are
guaranteed to be constructed before any function in a translation unit
is called. Hence, those objects lucky enough to share a translation
unit with main are guaranteed construction before main.

I disagree with Alf that this forces a 'main'-centred design. That
pre-supposes a design based around globals, and even in a such a
design, it would be better to use singletons.

James





> Tony
>
> ---
> [ comp.std.c++ is moderated.  To submit articles, try just posting with ]
> [ your news-reader.  If that fails, use mailto:std-...@ncar.ucar.edu    ]
> [              --- Please see the FAQ before posting. ---               ]
> [ FAQ:http://www.comeaucomputing.com/csc/faq.html                     ]

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Tony" <rdnewsNOSPAM2006@sbcglobal.net>
Date: Wed, 22 Nov 2006 15:39:19 CST
Raw View
<tasjaevan@gmail.com> wrote in message
news:1164197213.593950.262130@b28g2000cwb.googlegroups.com...
>
>
> On Nov 22, 12:26 am, rdnewsNOSPAM2...@sbcglobal.net ("Tony") wrote:
>> ""Alf P. Steinbach"" <a...@start.no> wrote in
>> messagenews:4sflo4Fvec3aU1@mid.individual.net...
>>
>> > Problems: (A) having 'main' singled out as "the" startup function
>> > forces a
>> > 'main'-centered design, especially with respect to dynamic
>> > initialization
>> > of statics, where only those appearing in 'main's translation unit are
>> > guaranteed to occur before 'main' is entered,Only POD's I believe.
>> > Class objects are another story (?).
>>
>
> No. File-scope POD objects do not have dynamic initialisation.
>
> File-scope user-defined objects requiring dynamic initialisation are
> guaranteed to be constructed before any function in a translation unit
> is called. Hence, those objects lucky enough to share a translation
> unit with main are guaranteed construction before main.

'function' meaning C function and not class method? When is a C++
implementation allowed to delay construction of static class objects?

Tony

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: kuyper@wizard.net
Date: Wed, 22 Nov 2006 17:19:04 CST
Raw View
Tony wrote:
> <tasjaevan@gmail.com> wrote in message
> news:1164197213.593950.262130@b28g2000cwb.googlegroups.com...
.
> > No. File-scope POD objects do not have dynamic initialisation.
> >
> > File-scope user-defined objects requiring dynamic initialisation are
> > guaranteed to be constructed before any function in a translation unit
> > is called. Hence, those objects lucky enough to share a translation
> > unit with main are guaranteed construction before main.
>
> 'function' meaning C function and not class method?

The C++ standard doesn't and can't impose any restrictions on on C
functions, so this applies only to C++ functions. Even if it did apply,
the only objects that can be defined in the same translation unit as C
functions are C objects, which would all qualify as POD types under C++
rules, so even in that case dynamic initialization would not be an
issue.

Class member functions are functions, just as much as the ones defined
outside of a class, so this rule applies to both.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: rdnewsNOSPAM2006@sbcglobal.net ("Tony")
Date: Wed, 22 Nov 2006 00:24:49 GMT
Raw View
""Alf P. Steinbach"" <alfps@start.no> wrote in message
news:4sflo4Fvec3aU1@mid.individual.net...
>* Tony -> Francis Glassborow:
>>
>> What possibilities emerge when one throws the main() paradigm away?
>>
>> Pretend you know nothing of main() and then make it work a new way.
>
> Perhaps this has gone far enough?
>
> You leave us guessing what you could possibly mean.  Is Tony referring to
> Bertrand Meyer's "real systems have no top"?  Is Tony referring to the
> Unix heritage for 'main'?  Is it the syntax or the action that bothers
> Tony?  Does Tony actually mean anything (the focus on 'main' is seemingly
> inconsistent with the thread's much more general title)?

The question has evolved and narrowed to the issue of main(). I'm hoping
that
someone can make a case for main() or present alternatives. I don't know
why a simple question is seemingly so hard to grasp.

Tony

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: rdnewsNOSPAM2006@sbcglobal.net ("Tony")
Date: Wed, 22 Nov 2006 00:26:56 GMT
Raw View
""Alf P. Steinbach"" <alfps@start.no> wrote in message
news:4sflo4Fvec3aU1@mid.individual.net...

> Problems: (A) having 'main' singled out as "the" startup function forces a
> 'main'-centered design, especially with respect to dynamic initialization
> of statics, where only those appearing in 'main's translation unit are
> guaranteed to occur before 'main' is entered,

Only POD's I believe. Class objects are another story (?).

Tony

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: kuyper@wizard.net
Date: Wed, 22 Nov 2006 10:35:24 CST
Raw View
"Tony" wrote:
> The question has evolved and narrowed to the issue of main(). I'm hoping
> that
> someone can make a case for main() or present alternatives. ...

Within the scope of this discussion, it's trivial to make a case for
main(): it's infinitely superior to any alternative that you've
suggested (because you've failed to suggest any alternatives).

> ... I don't know
> why a simple question is seemingly so hard to grasp.

Because you haven't presented any handles to grasp it by.  Just because
a question is simple to ask doesn't mean it's easy to answer (or even
meaningful). Like the child's question "How high is up?", your question
is too vague and nebulous to answer in any meaningful sense.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]