🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #2165

hard bug

#2165
From: Stephen C. Pope
Date: Fri, 12 Jan 1990 07:35
63 lines
2225 bytes

on Thu, 11 Jan 90 14:53:07 EST,
tiemann@ai.mit.edu (Micheal Tiemann) said:

Micheal> Here's a C++ teaser.  What's wrong with the following code?

[ ... ]

Micheal> More precisely, when execution reaches Greyhawk,

Micheal> 	1.  Is `x' in scope?
Micheal> 	2.  If so, it is initialized?
Micheal> 	3.  Where and when is `x' destroyed?

Micheal> If the scope of `x' were limited to the scope of the for loop, none of
Micheal> these problems would be "interesting", and everything work work as one
Micheal> might expect.

That's one solution.  I'm always annoyed when I get bitten by my habit of
writing:

	for( int i = 0; i < stopval; ++i )

only to discover that i was defined in the previous for loop.


However, it seems to me that one would be better served to
consider:

	if( expr )
		simple_statement;
       [else
		simple_statement;]

to be equivalent to:

	if( expr )
	    {
		simple_statement;
	    }
       [else
	    {
		simple_statement;
	    }]

In this way, *any* definition is local to the if statement (the
block enclosing the if clause or the else clause).

By keeping the loop control variable of the for loop around
after the termination of the for loop seems pretty handy to avoid
things like assigning to a variable or an object of more
comprehensive scope as the last part of the loop body
before testing and exiting so that information can be passed out
of the loop body.  Of course, this can also be done by giving
the loop control object (or whatever else it might be) more
comprehensive scope, which is what I think you want to argue for.

Micheal> Michael

stephen pope
advanced computing lab - lanl
scp@acl.lanl.gov
Technical Details
Message-ID: <9001120735.AA01533@blanche.acl.lanl.gov>
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu.edu!bu-cs!snorkelwacker!apple!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!BLANCHE.ACL.LANL.GOV!scp
References: <9001111953.AA13433@apple-gunkies.ai.mit.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!attcan!uunet!bu.edu!bu-cs!snorkelwacker!apple!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!BLANCHE.ACL.LANL.GOV!scp
From: scp@BLANCHE.ACL.LANL.GOV (Stephen C. Pope)
Newsgroups: gnu.g++.bug
Subject: hard bug
Message-ID: <9001120735.AA01533@blanche.acl.lanl.gov>
Date: 12 Jan 90 07:35:12 GMT
References: <9001111953.AA13433@apple-gunkies.ai.mit.edu>
Sender: daemon@tut.cis.ohio-state.edu
Reply-To: scp@blanche.acl.lanl.gov
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 63