[M3devel] introducing VAR in more places?

Mika Nystrom mika at async.caltech.edu
Tue Feb 12 22:27:15 CET 2008


Jay writes:
>Mika your switch example, besides being invalid C++, is just not fair.
>I don't think people even think to write their code like that.
>Introducing variables at the top of a switch is rare, esp. initializing the=
>m.

The example didn't come out of nowhere.  I once, a very long time
ago, being a not completely competent C programmer, wrote a program
like that and spent quite a while debugging it before I realized
that the initializations weren't being called.  I think I was thinking
that initializations are like Fortran DATA statements, or at least
should be, in any civilized programming language.  If you're extending
the stack frame to make room for the declared variables, shouldn't
you be calling the initialization code, too?  Apparently not...

Another way of looking at it is that it was just one of those bizarre
little bugs that led me to program in Modula-3.  Actually, I remember
what finally drove me over the edge.  I had written a program to
make plots of large VLSI chips at very high resolution (300+
megapixel) using alpha blending, etc., and it was working wonderfully
(for years) on FreeBSD.  I tried to port it to Linux (trivial,
right?) and discovered that I couldn't write a bug-free generic
linked list library in C to save my life.  The data structures in
the program were a bit tricky because of the size of the database,
and the fact that I wanted to run it in a small amount of memory.
In those days the custom was you had one server with a large amount
of RAM (1GB) and a bunch of workstations with 64 or 128 MB.  My
goal was to run the program, which could take up to a week each
time, on the workstations rather than tying up the server (which
was busy with other stuff).  After I had finally debugged the last
memory problem with my program, I sat down and wrote a bug-free one
in about two days in Modula-3, a programming language that I
previously just vaguely knew as a "fancier Pascal".

    Mika




More information about the M3devel mailing list