From: "John S. Fine" Newsgroups: comp.os.msdos.djgpp Subject: Re: Optimizations Date: Sun, 27 Sep 1998 20:27:09 -0400 Lines: 41 Message-ID: <360ED7DD.46AC@erols.com> References: <3606914B DOT 62A6 AT erols DOT com> <360EC4EE DOT 52F3BE6E AT unb DOT ca> Reply-To: johnfine AT erols DOT com NNTP-Posting-Host: 207-172-241-46.s46.as5.bsd.erols.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Endlisnis wrote: > > John S. Fine wrote: > > > > that the functions called inside the loop have no side effects, by > > > declaring it with __attribute__((const)). This is described in GCC docs, . . . > > All of my routines in the entire project have side effects. > > I hope you don't take this the wrong way (and you undoubtably will), but I > would call that bad programming structure. Side effects are bad things. I guess I am taking it the "wrong way". I take it as an indication that you don't know what "side effects" means in the context of a compiler's optimization, and that you didn't look at the other posts within the thread in which it was explained, and that you didn't look at the GCC docs (as suggested by the post I was replying to). > are some times when they are hard (or impossible) to avoid, but attempts should > be made. That's one of the big ideas behind Object oriented programming. It > divides data which needs to be accessed by many programs into logical chunks > that can only be accessed by the required functions. Object oriented programming does nothing to reduce side effects. In fact, there are a few cases in which it will increase side effects. If there exists data read or written by a routine other than what is pushed on the stack by the invokation or returned as the result, then from a compiler's point of view those are side effects. It doesn't help in the least if that data is cleanly hidden from the programmer. Routines that do simple computations (like sin or cosin) have no side effects. Routines that read or write files (or keyboards or screens or serial ports etc.) have side effects. Routines that format data into buffers have side effects. Routines that sort arrays have side effects. Nearly every routine a typical program calls has side effects. -- http://www.erols.com/johnfine/ http://www.geocities.com/SiliconValley/Peaks/8600/