Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!mit-eddie!mit-amt!peter From: peter@mit-amt.MEDIA.MIT.EDU (Peter Schroeder) Newsgroups: comp.lang.c++ Subject: Re: Constant Question Message-ID: <1466@mit-amt.MEDIA.MIT.EDU> Date: 23 Jan 90 16:20:31 GMT References: <130286@sun.Eng.Sun.COM> Organization: MIT Media Lab, Cambridge, MA Lines: 58 Sender: Reply-To: peter@media-lab.media.mit.edu (Peter Schroeder) Followup-To: Distribution: Organization: MIT Media Lab, Cambridge MA Keywords: const Ok, I'll bite my tongue off... In article <1103@etnibsd.UUCP> vsh@etnibsd.UUCP (Steve Harris) writes: >In article <1405@mit-amt.MEDIA.MIT.EDU> peter@media-lab.media.mit.edu (Peter Schroeder) writes: >>In article <130286@sun.Eng.Sun.COM> rbogen%dreams@Sun.COM (Richard Bogen) writes: main() { const float PI = 3.14159; float *const ptr = &PI; *ptr = 0.0; printf("%PI = %f\n",PI); } [some smart comments of mine] main() { const float PI = 3.14159; const float *ptr = &PI; *ptr = 0.0; // error printf("%PI = %f\n",PI); } >Peter corrected the code, but didn't answer the question! Well, umh, ... So, I just ran this through cfront 2.0 with float *const ptr = &PI; I do not get a complaint and it prints 0.0. Now that is a bug as far as I am concerned. If I write float *ptr = &PI; the compiler complains (rightly so). >My g++ generates a warning at line 2, and creates a second object for ptr >to point to, so PI remains unchanged and *ptr is initalized to 3.14159 but >then is changed to 0.0. I am not sure I would like that, at least not without a warning about using an intermediate. Peter peter@media-lab.media.mit.edu