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 

Jump past initialization of local variable with static stora

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





PostPosted: Thu Feb 12, 2004 11:17 pm    Post subject: Jump past initialization of local variable with static stora Reply with quote



When jumping past initialization of a local static variable the
value of the static becomes indeterminate. Seems like this
behavior should be illegal just as it is for local variables
with automatic linkage.

Should 6.7 P3 be changed to say "local variable with automatic
or static storage duration"? Or, is this behavior a
"quality of implemenation issue" which may be covered in
6.7 P4? Paragraph 4 seems to make the choice of static/dynamic
initialization indeterminate and would give different results here.

struct X {
X(int i) : x(i) {}
int x;
};
int f(int c) {
if (c)
goto ly; // error here for jumping past next stmt?
static X a = 1;
ly:
return a.x; // either 1 or 0 depending on implementation.
}

I've seen a similar test that uses a switch statement to duplicate
this behavior -- it is not limited to just (evil) gotos.

--
Kerch Holt [email]kerch (AT) cup (DOT) hp.com[/email]
HP Java, Compilers, and Tools Lab (JCTL)
11000 Wolfe Road, MS 4023
Cupertino, CA 95014


---
[ 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.jamesd.demon.co.uk/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.