[comp.lang.modula2] HEADER FILES

JOLINK@p0.f42.n105.z1.fidonet.org (JOLINK) (04/25/90)

From: JOLINK@RULCRI.LEIDENUNIV.NL
Date: 23 Apr 90 13:35:00 GMT
Organization: The Internet
Message-ID: <A5D0922064BF20497E@rulcri.LeidenUniv.nl>
Newsgroups: comp.lang.modula2

> >A C header file (that's the proper name, not 'include file')
> >is equivalent to a Modula-2 definition module.
> >It is NOT equivalent to an implementation module.
> >And you certainly can't link it in, neither in whole nor
> >in parts.
>
> Sorry, but the target of the #include directive can be pretty much
> *anything*. By *tradition*, C header files are just lists of constants
> and function prototypes (which arguably *would* make them equivalent
> to Modula-2 definition files). But that's just *tradition*. A header
> file *can* include full procedure bodies ... the one that was given
> for our latest assignment in one of my classes does. I have *never*
> seen a C compiler that would forbid that. (I've used Turbo C and
> Microsoft C on PCs and two different C compilers on UNIX.)

Neither have I. And I do not mean to point out the difference
between preprocessor and compiler here, I just agree.
It is a bit more than tradition, it is the accepted C style,
It is quite mandatory even: first of all, it is clearer,
it reflects the same design considerations as Modula-2's
definition module. You can indeed misuse the limited checking
(let's call it that for now) of the C compiler to include
a function from a header file, but your professor should
give you a minus for it. And, if you try to include the
header file twice, you will get a function redefinition warning.
The compiler is all that stupid, it does not do all the
error checking Modula-2 does, but not nothing either.
On small project, there is no bother, on big project you'll
be warned anyway.
There good C and bad C, just like there is good and bad
Modula-2, Pascal, whatever.

> I believe that C's #include is just a *compiler directive*. I think it
> has the exactly same effect as going into your program and inserting the
> text of the target file (like a xi in emacs). C's include does *not*
> have anything like the richness and power of Modula-2's definition
> files.

Preprocessor directive. It has more power: you can even include
functions in your header files... :-).  And it does a lot more
than just including the text into your program. It really offers
some capabalities only a preprocessor can give you.

> >The discussion whether Modula-2 and/or C do or do not
> >link in whole libraries is totally beside the point.
> > ... SOME STUFF DELETED...
>
> I would take issue with part of the above. Modula-2's IMPORT is *not*
> a warmed-over compiler directive, like C's #include; it controls
> *which public symbols* in the definition/implementation modules are to
> be visible to your program.
> Reusing code and linking together separate modules is something you
> have to do by hand in C. But since the IMPORT is part of the Modula-2
> language, most *decent* Modula-2 compilers (eg, the two I've used on
> PCs but *none* of the ones I've used on minicomputers) do the linking
> automatically. So while C (and most minicomputer compilers) force you
> to do your own linking, decent Modula-2 compilers don't require you to
> even *know* what linking is.

It is not a compiler directive at all, and certainly not a warmed-over one.
Modula-2's IMPORT  arguably is, The C #include directive is different.
It is cold preprocessing. You seem to reason like this: In M2
I can define a constant in a definition module and import exactly
what I like. The C preprocessor does not match that. But in C you
can declare a constant where you need and define it as static:
no other .c file that compiles to an .obj file will see that variable.
The same goes for functions etcetera. No, it's not exactly the
same, it does not have exactly the same power, but it offers
most, if not all, of the needed functionality.

Most modern C compiler do not require you to know what linking is
either. But that is hardly a pluspoint, is it? We are not just users,
we are programmers. We should care about things like that.

#include is part of the C preprocessor, which is part of the
C language. Linking in the right object files is a bit of problem
in C, that's why C programmer's have MAKE, which automates the
process.
u



--  
uucp: uunet!m2xenix!puddle!42.0!JOLINK
Internet: JOLINK@p0.f42.n105.z1.fidonet.org