Re: [OT] What is a 'header' file?

new topic     » goto parent     » topic index » view thread      » older message » newer message

ZNorQ wrote:
> 
> Mario Steele wrote:
> > 
> > ZNorQ wrote:
> > > 
> > > Derek Parnell wrote:
> > > > 
> > > > ZNorQ wrote:
> > > > > 
> > > > > I'm not quite sure what a header file is.
> > > > 
> > > > Header files are used by the C and C++ languages. 
> > > > 
> > > > They generally contain definitions that are used by a C/C++ program.
> > > > Specifically
> > > > they contain definitions of routines but without the actual details of
> > > > the
> routines'</font></i>
> > > > implementation, just the name, return type, and parameter signature. For
> example...</font></i>
> > > > 
> > > >    int foo(char *, int);
> > > > 
> > > > This says that there is a routine called 'foo' that returns an 'int' and
> > > > accepts
> > > > as parameters a pointer to a 'char' and an 'int', declared somewhere
> > > > else.
> The</font></i>
> > > > compiler uses this information so that when it comes across a call to
> > > > the
> routine,</font></i>
> > > > it can validate the parameters on the call, and how the return value is
> > > > handled.
> > > > It can do this before it eventually comes across the actual routine's
> > > > implementation
> > > > details.
> > > > 
> > > > A header file might also contain struct and class definitions, but again
> > > > it
> > > > doesn;t have to have implementation details, just the layout of the data
> > > > items
> > > > in them.
> > > > 
> > > > eg.
> > > > 
> > > >    class Bar {
> > > >        int abc;
> > > >        char* ddd;
> > > >        float xyz;
> > > >     }
> > > > 
> > > > Then, when the compiler comes across a reference to an object of the
> > > > class
> 'Bar',</font></i>
> > > > it knows enough to check that the reference is valid.
> > > > 
> > > > Header files are useful for single pass compilers because it means that
> > > > it
> can</font></i>
> > > > deal easily with forward references.
> > > > 
> > > > Header files are not needed for multiple pass compilers.
> > > > 
> > > > 
> > > > -- 
> > > > Derek Parnell
> > > > Melbourne, Australia
> > > > Skype name: derek.j.parnell
> > > 
> > > Ok. As for Euphoria, are we just talking about include files in general,
> > > or
> > > would there be a categorization between an include file containing a
> > > collection
> > > of procedures and functions, and those who acts like interfaces between Eu
> > > and
> > > DLLs? 
> > > 
> > > Kenneth/ZNorQ
> > 
> > In Euphoria, there is no specific "header" file type.  All includes contain
> > code in them.  There would be no need for that distinction.  You can write
> > code
> > to link between Euphoria and a DLL/SO, directly into the main ex/exw/exu
> > file,
> > and it would work just as fine, if you write it in a e/ew file.  So there's
> > no direct corilation between a "header" file that is used by C and Euphoria.
> > 
> > Mario Steele
> > <a
> > href="http://enchantedblade.trilake.net">http://enchantedblade.trilake.net</a>
> > Attaining World Dominiation, one byte at a time...
> 
> Ok, thanks for the feedback, Mario. :)
> 
> Kenneth/ZNorQ

As Derek said, header files are useful to give single pass compilers (which the
Eu parser is) hnts about symbols it may find referenced without a definition.

Thus, in order to allow forward referencing of routines or variables, one could
either:

1/ declare the symbol before it is used, but define it later, with a syntax
like:
forward procedure foo(integer n)
-- ....
foo(2)
-- interpreter doesn't know what foo() does, but can check the call is correct
p=routine_id("foo")
-- correct, foo() exists. Again, what it does doesn't need to be known at this
point - we are still parsing
-- ....
procedure foo
bar(n)
?123
nd procedure


This is handy, but require a specific "forward" keyword. Thats how it is
implmented in Æ. Pascal does it this way too.

The other approach is to define a header file:
-- myprog.eh
procedure foo(integer n)

-- myprog.exw
include_header myprog.eh
-- ...
foo(3)-- correct, was referenced in header file
-- ...
procedure foo
bar(n)
?123
nd procedure


include_header is needed vs include, as the header fle does not contain
definitions. Alternately, it might start with a special directive, in which case
a simple include statement would be good.  C does it this way.

Both approaches work.

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu