M
Montezuma's Daughter
Hi All
I was wondering why h file ia needed?
why can't everything be written in C file?
thanks
I was wondering why h file ia needed?
why can't everything be written in C file?
thanks
Montezuma's Daughter said:I was wondering why h file ia needed?
why can't everything be written in C file?
Hi All
I was wondering why h file ia needed?
why can't everything be written in C file?
thanks
We don't disscuss C files, source files are typically *.cpp files in C+
+
Funny thing, many compilers treat .C files as C++.
they do, i didn't say .C files
Montezuma's Daughter said:Hi All
I was wondering why h file ia needed?
why can't everything be written in C file?
thanks
Jim Langston said:.h files are not needed, they are desired. Consider a program that includes
two different .cpp or .c files. This will normally create two object files.
Consider that one of the source files declares some functions.
int foo( int x ) { /*...*/ };
char* bar() { /* ... */ };
and such. Now, without a header file you will need to declare the
prototypes in the other source file.
int foo( int x );
char* bar();
There can be many functions, structures and the like and you would have to
check the source file and copy lines for each one you wanted to call. This
is where a header file comes in. A header file is basically just a list of
prototypes and structures used in some object file (or library) that you can
include in your source file without having to type them in manually each
time.
If you are only using one source file and no others, you could get away with
not including header files for your code, but would probably still need to
include header files for the system files, stdio.h, memory.h and the like.
These are prototypes and such for system/core functions.
Pete said:I didn't say that you did. I merely hinted that maybe you were focusing
on the wrong aspect of the orginal question.
On 2008-01-08 14:15:06 -0500, Salt_Peter <[email protected]> said:
Funny thing, many compilers treat .C files as C++.
Well, with some IDE, you could have your sources in a
database, where no source or header file would be defined
really. You could then just define the compilation units (or
let the IDE do it for you), and the IDE would generate a
single source file for each compilation unit, containing all
the declarations and definitions needed.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.