🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

static initialization

#524
From: Doug Schmidt
Date: Sun, 22 Oct 1989 01:10
35 lines
1473 bytes
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.

Doug
--
Master Swordsman speak of humility;             | schmidt@ics.uci.edu (ARPA)
Philosophers speak of truth;                    | office: (714) 856-4034
Saints and wisemen speak of the Tao of no doubt;
The moon, sun, and sea speaks for itself. -- Hiroshi Hamada
Technical Details
Message-ID: <1989Oct21.181007.10849@paris.ics.uci.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!uwm.edu!uakari.primate.wisc.edu!ginosko!usc!orion.oac.uci.edu!uci-ics!usenet

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!uwm.edu!uakari.primate.wisc.edu!ginosko!usc!orion.oac.uci.edu!uci-ics!usenet
From: schmidt@glacier.ics.uci.edu (Doug Schmidt)
Newsgroups: gnu.g++.bug
Subject: static initialization
Message-ID: <1989Oct21.181007.10849@paris.ics.uci.edu>
Date: 22 Oct 89 01:10:07 GMT
Reply-To: schmidt@glacier.ics.uci.edu (Doug Schmidt)
Distribution: gnu
Organization: University of California, Irvine - Dept of ICS
Lines: 35