Mail Archives: djgpp/1998/09/28/05:48:56
On Sun, 27 Sep 1998, John S. Fine wrote:
> 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.
The last assertion is too broad to be true. There's still a lot a
programmer can do to minimize the side effects (if this is at all a
goal of that programmer). It is true that functions that do I/O have
side effects that can hardly be avoided, but some other examples you
cite can certainly be designed and written in a way that doesn't have
side effects as far as GCC is concerned. For example, a function that
sorts a buffer can return the sorted buffer as its value, and then it
has no side effect in the context of this discussion (i.e., you can
declare it with a const attribute).
In fact, languages such as Lisp and LOGO actively force you into such
paradigms.
- Raw text -