Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!kddlab!titcca!sragwa!wsgw!socslgw!diamond!diamond From: diamond@diamond.csl.sony.junet (Norman Diamond) Newsgroups: comp.lang.c++ Subject: Re: Possible error in Stroustrup ? Message-ID: <10330@socslgw.csl.sony.JUNET> Date: 5 Jun 89 05:12:59 GMT References: <774@batserver.cs.uq.oz> Sender: news@csl.sony.JUNET Reply-To: diamond@csl.sony.junet (Norman Diamond) Organization: Sony Computer Science Laboratory Inc., Tokyo, Japan Lines: 40 In article <774@batserver.cs.uq.oz> anthony@batserver.cs.uq.oz writes: >On page 205 of "The C++ programming language" by Stroustrup, there is >listing of a get function for circular list class slist. >ent slist::get() >{ > if (last == 0) slist_handler("get from empty slist"); > slink* f = last->next; > ent r = f->e; > last = (f==last) ? 0 : f->next; >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > delete f; > return r; >} >The line starting with "last = ...." seems to be wrong. The function >get is suppose to return and remove the head of the list. >Can anyone confirm this ? Looks to me like it was a bug, and it looks to me like it looked to Bjarne Stroustrup like it was a bug, too. In my copy of The Book, it now looks like: if (f == last) last = 0; else last->next = f->next; I guess it is no longer nececessary to get the wrong answer in as few lines as possible. Once upon a time, someone suggested testing examples before publishing them. Does no one learn? -- Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.co.jp@relay.cs.net) The above opinions are my own. | Why are programmers criticized for If they're also your opinions, | re-implementing the wheel, when car you're infringing my copyright. | manufacturers are praised for it?