Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!cbosgd!ihnp4!inuxc!pur-ee!uiucdcs!uiucdcsb!kenny From: kenny@uiucdcsb.cs.uiuc.edu Newsgroups: comp.lang.c++ Subject: Why put constants on the stack? Message-ID: <165700009@uiucdcsb> Date: Wed, 27-May-87 16:25:00 EDT Article-I.D.: uiucdcsb.165700009 Posted: Wed May 27 16:25:00 1987 Date-Received: Wed, 10-Jun-87 06:02:21 EDT Lines: 29 Nf-ID: #N:uiucdcsb:165700009:000:1114 Nf-From: uiucdcsb.cs.uiuc.edu!kenny May 27 15:25:00 1987 Running 1.1 (so I don't know whether this has been fixed yet): When a local variable is declared ``const,'' the compiler appears to assume that it is automatic as well. This leads to the following anomaly: -------------------- bad.c -------------------- main () { const int array [] = { 1, 2, 3 }; } CC bad.c: "bad.c", line 3: sorry, not implemented: initialization of automatic aggregates "bad.c", line 3: sorry, not implemented: initializer list for local variable array 2 errors -------------------- good.c ------------------- main () { static const int array [] = { 1, 2, 3 }; } (compiles cleanly) ----------------------------------------------- Why are ``const'' variables (other than parameters, of course) not assumed to be static? In addition to the above annoyance, it seems like a pointless waste of stack space. Have I overlooked something? Kevin Kenny UUCP: {ihnp4,pur-ee,convex}!uiucdcs!kenny Department of Computer Science ARPA: kenny@B.CS.UIUC.EDU (kenny@UIUC.ARPA) University of Illinois CSNET: kenny@UIUC.CSNET 1304 W. Springfield Ave. Urbana, Illinois, 61801 Voice: (217) 333-8740