1. [OT] What is a 'header' file?
- Posted by ZNorQ <znorq at ?olhau?.com> Jun 04, 2008
- 801 views
This might sound abit stupid, but I'm not quite sure what a header file is. As far as I can see, its one of 3 categories; 1) An include file that acts as an interface between for example Euphoira and a DLL file, somewhat like Win32Lib? 2) An include file that contains pure source code. 3) All of the above. Kenneth/ZNorQ
2. Re: [OT] What is a 'header' file?
- Posted by Derek Parnell <ddparnell at big?o?d.com> Jun 04, 2008
- 770 views
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' implementation, just the name, return type, and parameter signature. For example... 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 compiler uses this information so that when it comes across a call to the routine, 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', it knows enough to check that the reference is valid. Header files are useful for single pass compilers because it means that it can deal easily with forward references. Header files are not needed for multiple pass compilers. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell
3. Re: [OT] What is a 'header' file?
- Posted by Mario Steele <eumario at tr??ake.net> Jun 04, 2008
- 728 views
Hello Kenneth, It actually depends on the Programming Language, but in general cases, a header file refers to C/C++ in majority, which is the way to expose C functions and procedures to other parts of the source code. If a C function define in say a.c, and b.c tries to use the same function, but there is no a.h, the C Compiler will complain about it being an undefined function. However, if a.h exists, and b.c includes a.h, then b.c will be able to use the function defined in a.c, and the compiler will know where to find it. This is how the C pre-processor was designed, and remains true for any derivitive of the C Language, AFAIK. *goes back to lurking* Mario Steele http://enchantedblade.trilake.net Attaining World Dominiation, one byte at a time...
4. Re: [OT] What is a 'header' file?
- Posted by ZNorQ <znorq at holhau??com> Jun 04, 2008
- 725 views
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' > implementation, just the name, return type, and parameter signature. For > example... > > 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 > compiler uses this information so that when it comes across a call to the > routine, > 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', > it knows enough to check that the reference is valid. > > Header files are useful for single pass compilers because it means that it can > 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
5. Re: [OT] What is a 'header' file?
- Posted by Mario Steele <eumario at tri?a?e.net> Jun 04, 2008
- 754 views
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' > > implementation, just the name, return type, and parameter signature. For > > example... > > > > 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 > > compiler uses this information so that when it comes across a call to the > > routine, > > 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', > > it knows enough to check that the reference is valid. > > > > Header files are useful for single pass compilers because it means that it > > can > > 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 http://enchantedblade.trilake.net Attaining World Dominiation, one byte at a time...
6. Re: [OT] What is a 'header' file?
- Posted by ZNorQ <znorq at holha?g?com> Jun 04, 2008
- 760 views
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' > > > implementation, just the name, return type, and parameter signature. For > > > example... > > > > > > 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 > > > compiler uses this information so that when it comes across a call to the > > > routine, > > > 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', > > > it knows enough to check that the reference is valid. > > > > > > Header files are useful for single pass compilers because it means that it > > > can > > > 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
7. Re: [OT] What is a 'header' file?
- Posted by CChris <christian.cuvier at ag?iculture?gouv.fr> Jun 04, 2008
- 767 views
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
8. Re: [OT] What is a 'header' file?
- Posted by Matt Lewis <matthewwalkerlewis at gmail??om> Jun 04, 2008
- 741 views
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. <snip> > Then, when the compiler comes across a reference to an object of the class > 'Bar', > it knows enough to check that the reference is valid. > > Header files are useful for single pass compilers because it means that it can > deal easily with forward references. > > Header files are not needed for multiple pass compilers. Yeah, but it's a bit more than that, because to build a C/C++ executable, compiling isn't enough. Basically, the compiler compiles each .c/cpp/etc file into an object file, then it links them all together. Before the linking, none of the object files really know about each other, except from what they've heard from header files. Some of the references might also be resolved to dynamic/shared libraries. Matt
9. Re: [OT] What is a 'header' file?
- Posted by Fernando Bauer <fmbauer at hotma?l.c?m> Jun 04, 2008
- 747 views
Matt Lewis 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. > > <snip> > > > Then, when the compiler comes across a reference to an object of the class > > 'Bar', > > it knows enough to check that the reference is valid. > > > > Header files are useful for single pass compilers because it means that it > > can > > deal easily with forward references. > > > > Header files are not needed for multiple pass compilers. > > Yeah, but it's a bit more than that, because to build a C/C++ executable, > compiling isn't enough. Basically, the compiler compiles each .c/cpp/etc > file into an object file, then it links them all together. Before the > linking, > none of the object files really know about each other, except from what > they've heard from header files. Some of the references might also be > resolved to dynamic/shared libraries. > > Matt Also, C header files help us to follow the "Don't Repeat Yourself" principle: they can contain in one place symbols and macros declarations used by several modules which form the program. Thus, the software creation and the software maintenance is facilitated. - Fernando
10. Re: [OT] What is a 'header' file?
- Posted by Chris Bensler <eu at creat?veporta?.ca> Jun 04, 2008
- 784 views
Hi Kenneth, What the others said was all true, but I think what you are actually interested in is how do C header files relate to Euphoria? In a nutshell, a header file is a declaration of everything that is exported from a dll or object file. In Euphoria, we use the header files as references to what must be imported for us to be able to use a dll. The header file provides all the information we need to be able to interface with the dll. C does the same thing, but the compiler handles the headers automatically. In Euphoria, we must manually translate those headers into Eu code. The euphoria equivalent of a header file would be a specialized library that some people call a 'wrapper' or 'binding' or 'abstraction layer'. It bridges the gap between the euphoria code and the dll by defining the routines, types and constants that are available in the header file (that are available in the dll actually) as eu code. These routines are just abstractions that we use to hide all the the dirty C code interfacing that we have to do from eu. For example: Without any wrappers, we could call the WinVer() function from the windows dll's with something like this.. ret = c_func(USER32_DLL,"WinVer",{}) This is not very elegant though, so people generally make a wrapper function to make it more 'euphoric'... function WinVer() return c_func(USER32_DLL,"WinVer",{}) end function Usually you don't even need the header file to be able to create a wrapper if the documentation for the API is adequate, but often certain details are omitted, like the real values of the constants and the authentic names of the API's functions. All functions in the windows API that do any string handling have a couple different versions for example, depending on how the API is configured for compilation. The windows function: CreateWindowEx() is how we would find it in the API documentation, but in the headers, there is two routines.. CreateWindowExA() and CreateWindowExW() for ANSI and UNICODE respectively. One of those is mapped to a macro called CreateWindowEx(), depending if you have enabled unicode strings or not. So, in Eu we could create a function such as.. function CreateWindowEx(atom arg1, atom arg2, ...) return c_func(USER32_DLL,"CreateWindowExA",{arg1, arg2, ...}) end function or if we want the wrapper to be as flexible as the C headers, we could create 3 functions along with a flag to indicate if unicode is default or not. constant UNICODE = 0 function CreateWindowExA(atom arg1, atom arg2, ...) return c_func(USER32_DLL,"CreateWindowExA",{arg1, arg2, ...}) end function function CreateWindowExW(atom arg1, atom arg2, ...) return c_func(USER32_DLL,"CreateWindowExW",{arg1, arg2, ...}) end function function CreateWindowEx(atom arg1, atom arg2, ...) if UNICODE then return c_func(USER32_DLL,"CreateWindowExW",{arg1, arg2, ...}) else return c_func(USER32_DLL,"CreateWindowExA",{arg1, arg2, ...}) end if end function Hope That Helps, Chris Bensler Code is Alchemy