[COFF] [TUHS] C vs Pascal thoughts - was Buffer overflow found/fixed in v4 tape ; )
Dan Cross via COFF
coff at tuhs.org
Wed Jan 7 02:53:51 AEST 2026
On Tue, Jan 6, 2026 at 11:38 AM Paul Winalski via COFF <coff at tuhs.org> wrote:
> On Mon, Jan 5, 2026 at 5:31 PM Bakul Shah via COFF <coff at tuhs.org> wrote:
> > 2.2 static variables -- I tend to believe using static vars is usually
> > a mistake. Initialization -- saves some typing but that is about it.
>
> Static variables are useful where a subroutine must retain context between
> invocations. For example, the seed for a pseudo-random number generator.
Surely one could do that with a global, as well.
Common Lisp had an interesting mechanism that one could pervert^Wuse
for such things, without using a dynamic variable: define a function
inside of a `let`:
```
*
(let ((a 0))
(defun incr ()
(setf a (+ a 1))
a))
INCR
* (incr)
1
* (incr)
2
* (incr)
3
*
```
I briefly wondered if Pascal's support for lexically nested functions
might be leveraged for something like this: presumably the "inner"
function could treat the outer function's variables like statics, but
given that the inner functions are not themselves directly accessible,
I don't think so; they're not closures.
- Dan C.
More information about the COFF
mailing list