Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!purdue!ames!uhccux!munnari.oz.au!mimir!hugin!augean!sirius!nt!levels!mardm From: mardm@levels.sait.edu.au Newsgroups: comp.lang.c++ Subject: Problem with Zortech C++ Message-ID: <937@levels.sait.edu.au> Date: 31 Jul 89 16:31:50 GMT Organization: Sth Australian Inst of Technology Lines: 77 I've discovered what could be a problem in the Zortech C++ Compiler (1.07e). Heres the CPP program: (small memory model) //---------------- #include class TestClass { int im_current; public: void PrintTheItem(const int which); TestClass(); }; void TestClass::PrintTheItem(const int which) {printf("%d ",which); } TestClass::TestClass() { im_current=1234; for (int menu_selection=1;menu_selection<10;menu_selection++) {printf("Setting..."); PrintTheItem(im_current); im_current=menu_selection; PrintTheItem(im_current); printf("\n"); } } main() {TestClass * mymenu = new TestClass(); delete TestClass; } Heres the output I get when I run it WITHOUT the optimiser: Setting...1234 1234 Setting...1 1 Setting...2 2 Setting...3 3 Setting...4 4 Setting...5 5 Setting...6 6 Setting...7 7 Setting...8 8 ...and heres the (expected) output which I do get when I run it WITH the optimiser. Setting...1234 1 Setting...1 2 Setting...2 3 Setting...3 4 Setting...4 5 Setting...5 6 Setting...6 7 Setting...7 8 Setting...8 9 It appears the assignment to im_current in TestClass() does not actually occur until the end of the loop. Note that getting rid of the "const" in the declaration of PrintTheItem fixes the problem. O.K. so the obvious "solution" is to use the optimiser! But I can't afford the time (the system takes > 20 minutes to fully compile as it is). Oh yes, my setup: 12MHz AT Compat, 66 Meg Voice Coil HD with Cache & Co-Processor. Thanks for any help... Riccardo Macri, Graduate, C++ Programmer (S/W Development) S.A.I.T. (Levels) mardm@levels.sait.oz