#Modula-2 Programming
4 messages in this thread
Interesting comments…When I mentioned 50,000 lines programs I didn't mean a
single module (that is of course ridiculous). Also, I'm not that familiar with
FUNCTION PROTOTYPING in C. What is it? Also what's the difference between
compile error or a warning, if your program will not run. The fact that some of
ideas that first appeared in C, are also present in Modula-2, just means that
Wirth is a smart guy. He saw something good and used it. I prefer Modula-2,
because I think it saves me a lot of work…and I still say that any compile
error is much easier to fix than a runtime error, even when you have great
debuggers……Richie
Function prototyping in C (only necessary, of course, in multiple module
compilations, or "forward" declarations. Not really "forward", since it's
basically just a compiler directive; C does all function name resolution at
link time) lets me declare a function's type and number of parameters, for type
checking purposes. So I can place a:
extern struct Window *OpenWindow(struct NewWindow *);
in my program, and the compiler will then know the number and types of
arguments. I could legally do something like:
{ long goofy; struct NewWindow *smart;
…
goofy = smart;
window = OpenWindow(goofy);
… }
which will generate error messages for the type conflicts, but will also
produce correct code. Now, that's certainly very sloppy. So it lots of old C
code, some of which counts on the fact that default function return value is
int, and on some machines sizeof(int) == sizeof(valid_machine_address) Now,
anyone still writing C code like that is either doing it for some specific
reason (force of habit?) or looking for trouble. The type checking is all I
really want; saves my butt on many occasions. I don't really need to be forced
into it.
-Dave
Thanks for the desription of "function prototyping" in C. However, it doesn't
look that useful. It's just like external declarations in many PASCAL compilers
I used. WHen you get around to writing the code for the prototyped function,
does the compiler check then that you declared it in the same way? If, not then
function prototyping doesn't buy you much. In Modula-2 the definition module
specifies the procedure declarations (which is kind of like your extern
declaration) but the compiler checks that the function is used properly by all
callers, and it also checks that it's implemented according to the declaration.
One further thing Modula-2 does, is that if you change your function and forget
to recompile one of the 30 modules that use it, when you link your program you
will get a link error saying "module so-and-so is not compatible, please
recompile". I think that's a great work saver….Richie
The compiler will check to see if your declaration prototypes, all invocations,
and you definition of the function all match. And I do like the smartness
Modula2 puts into it's linking. The best thing you can do in C is define your
Makefile to reflect all dependencies. Of course, like the prototyping in C,
that's optional, not required, and not automatic. I wouldn't mind that part
happening automatically, cause dependencies sometimes change faster than the
Makefile does.
-Dave