Article View: gnu.g++.bug
Article #540Re: static initialization
From: mx!cbcscmrs
Date: Tue, 24 Oct 1989 03:35
Date: Tue, 24 Oct 1989 03:35
49 lines
2149 bytes
2149 bytes
In article <1989Oct21.181007.10849@paris.ics.uci.edu> schmidt@glacier.ics.uci.edu (Doug Schmidt) writes:
+----
| If you want some fun, try guessing what the `correct' output should be
| for the following C++ code accepted without warning from G++. Then
| compile and execute it with G++ and check your work.
|
| ----------------------------------------
| #include <stdio.h>
|
| int *frob(int k)
| {
| static int N[2] = {k, k};
| return N;
| }
|
| main ()
| {
| int i;
|
| for (i = 5; i < 10; i++)
| printf ("i = %d\n", frob(i)[1]);
| }
| ----------------------------------------
|
| cfront 2.0 complains:
|
| "yow.c", line 13: sorry, not implemented: local name k in initializer for static
|
| I think I like the G++ solution, although it is not clear exactly what
| the `official' output should be.
+----
Well, I just check it, and I looked at the semantics embodied in the assembly
code it generated. It does what I expected it too. (Going on the assumption
that it would generate code.) I think for what it does, it does it well.
The only gripe that I can see is the gripe about a warning message to the
effect: ``warning: only first initialization will be used to initialize
object.''
Others? How do you feel?
Spoiler follows:
For those that don't have g++-1.36 (or later) the program outputs a bunch
of 5s. The code that is generated allocates an unnamed temporary initialized
to zero, and when the function is called and the statics initialized, the
temporary is changed to one. It only initializes the static object if the
temporary is zero.
Technical Details
Message-ID:
<2427@csun.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!snorkelwacker!tut.cis.ohio-state.edu!cs.utexas.edu!ginosko!usc!csun!mx!cbcscmrsReferences:
<1989Oct21.181007.10849@paris.ics.uci.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!snorkelwacker!tut.cis.ohio-state.edu!cs.utexas.edu!ginosko!usc!csun!mx!cbcscmrs From: mx!cbcscmrs@csun.edu Newsgroups: gnu.g++.bug Subject: Re: static initialization Message-ID: <2427@csun.edu> Date: 24 Oct 89 03:35:19 GMT References: <1989Oct21.181007.10849@paris.ics.uci.edu> Sender: news@csun.edu Reply-To: cbcscmrs@mx.csun.edu (Mike Stump) Distribution: gnu Organization: CSU, Northridge School of Engineering & Computer Science Lines: 49