C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Defect Report: ambiguity of "after the first statement of ma

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Alf P. Steinbach
Guest





PostPosted: Mon Oct 30, 2006 11:51 pm    Post subject: Defect Report: ambiguity of "after the first statement of ma Reply with quote



§3.6.2/3 [basic.start.init], about initialization of non-local objects:

"If the initialization is deferred to some point in time after the
first statement of main, it shall occur before the first use of any
function or object defined in the same translation unit as the object
to be initialized."

Presumably the intent is to allow deferred initialization, such as with
a dynamically loaded library, e.g. MSVC's "delay load" mechanism.

A literal reading says however that this support is limited to /after/
the first statement of main, i.e., the initialization cannot occur
/during/ the first statement of main, which seems to be meaningless.

To avoid that one must interpret, on the basis of presumed intent.

Suggested rewording:

"... some point in time after /execution of/ the first statement of
main /has started/, ..."

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

---
[ 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 ]
Back to top
Greg Herlihy
Guest





PostPosted: Sat Nov 04, 2006 8:02 pm    Post subject: Re: Defect Report: ambiguity of "after the first statement o Reply with quote



"Alf P. Steinbach" wrote:
Quote:
§3.6.2/3 [basic.start.init], about initialization of non-local objects:

"If the initialization is deferred to some point in time after the
first statement of main, it shall occur before the first use of any
function or object defined in the same translation unit as the object
to be initialized."

Presumably the intent is to allow deferred initialization, such as with
a dynamically loaded library, e.g. MSVC's "delay load" mechanism.

I'm not so sure. It seems more likely to me that the purpose is to
support "lazy" initialization of objects - that is, to defer
initialization of an object until the program needs the object.

Quote:
A literal reading says however that this support is limited to /after/
the first statement of main, i.e., the initialization cannot occur
/during/ the first statement of main, which seems to be meaningless.

The granularity of the paragraph here is definitely odd. It would seem
that a description at the function call level (such as "after main has
been entered") would be more appropriate here than the current,
statement-level description. Unless the intent is to make a (very)
oblique point. I'm thinking that the reference to the "first statement"
of main may be implying that a program whose main() has no first
statement (that is, an empty main) would be exempt from the
initialization requirement being described. In other words, it is legal
for certain objects in a program not to have been initialized at all by
the time the program terminates.

Quote:
To avoid that one must interpret, on the basis of presumed intent.

Suggested rewording:

"... some point in time after /execution of/ the first statement of
main /has started/, ..."

I think that any statement-level description is likely to remain
somewhat confusing. The reader may well wonder what is the significance
of the first statement of main. It is exempt from this requirement? Or
is it prohibited from referring to uninitialized objects? What exactly
is the Standard getting at here?

So, if there is no sigificance to the statement-level description, then
replacing it with a higher level description would be my suggestion.
And even if that the Standard does want to single out an empty main()
as some kind of an exception, then a higher level description would
still be able to do so explicitly:

"If the initialization is deferred to some point in time after main has
been entered (and main is not empty), then the initialization shall
occur before the first use..."

Greg


---
[ 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 ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.