473,569 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header files

ben
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?

Next where can i find definition of functions defined in system header
files. I'm working on UNIX.

Thanx in advance.

--ben

Nov 8 '06 #1
7 2170
ben wrote:
I have few doubts about header files.
Is it true that header files always have only "function declaration"
and not definition?
No.

But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).
Next where can i find definition of functions defined in system header
files.
Why do you want them? Do you really want the definitions, or just a
description?
I'm working on UNIX.
(a) Typically those functions are described on manpages with staggeringly
obvious names.

(b) Different Unices will have those function definitions in different
places. If they ship them at all. They need not.

(c) There are publicly available sources for implementations of those
functions (note: not necessarily the ones on your Unix), eg and
in particular, glibc.

(d) Google is your nasal demon. I mean friend.

--
Chris ".enable proofreading" Dollin
Meaning precedes definition.

Nov 8 '06 #2


ben wrote On 11/08/06 10:23,:
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?
Usually true, but not "always" true.
Next where can i find definition of functions defined in system header
files. I'm working on UNIX.
One of the virtues of the "separate compilation" model
used by C and some other programming languages is that once
the "source code" has been compiled into "object code," you
no longer need the source: You just "link" the object code
from several compilations together, and there's your program.

Many systems take advantage of this ability to reduce the
amount of disk space needed: object code is usually much
smaller than source code, and since the object code is all
that's needed to run the program, why waste space on the
bulky source? Some Unix and non-Unix system providers may
also withhold the source code for commercial and licensing
reasons (or maybe to spare themselves embarrassment). The
upshot is that on many systems the source code won't be
present at all, or may be an "optionally installable" part
of the system distribution. On some systems, you may be
able to get the source code only by paying for it (and,
probably, by agreeing not to reveal it).

If the source for your system's libraries is available,
its location and form will be entirely system-dependent and
not dictated by the C language. (Indeed, the libraries might
not be written in C at all.) Try your question on a forum
dedicated to the particular Unix flavor you are interested in.

--
Er*********@sun .com

Nov 8 '06 #3

ben wrote:
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?
There is no hard and fast rule which say this. However, it is the
general
practice (for very good reasons) and in some cases it is required. For
instance, if you have a static variable declared and defined in a
header
file, and you include this header file in multiple *.c files, you may
get a
compilation error.
>
Next where can i find definition of functions defined in system header
files. I'm working on UNIX.
I am not sure about this one, I haven't looked for the source code. I
believe, if
you have open source version of libraries, while downloading you will
need to
specify to download the source code along with the libraries.
>
Thanx in advance.

--ben
Nov 8 '06 #4

ben wrote:
Hi,
I have few doubts about header files.

Is it true that header files always have only "function declaration"
and not definition?
Not necessarily, but in general it's a good practice for several
reasons.

First of all, header files can wind up being #included multiple times
in the same translation unit (this often happens when header files
include other header files). Multiple definitions of the same function
in the same translation unit will cause the compiler to complain (it is
possible to avoid this problem with guard macros).

Secondly, if the header is included in several translation units, each
translation unit will have a redundant definition of that function.
Some linkers will resolve the redundant definitions into a single
definition, some may not. Some may complain about the redundant
definitions. If nothing else, the redundant definitions take up space.
If a function needs to be shared between multiple translation units,
it's better to put the function definition in a translation unit of its
own, compile it separately, and link it as necessary. That way, it
only needs to be compiled once (as opposed to once for every
translation unit that includes it), and you don't have to worry about
linker behavior.

Life is easiest when header files describe interfaces, not
implementations . There's really nothing stoppping you from putting a
function definition in a header file, but most of the time it will lead
to heartburn.
Next where can i find definition of functions defined in system header
files. I'm working on UNIX.
The actual source code may not be available for your implementation,
and if it is, it may vary widely between implementations . If you want
to see some examples of how the standard library functions *may* be
implemented, find P. J. Plauger's "The Standard C Library."

Nov 8 '06 #5
In article <ei*********@ma latesta.hpl.hp. com>,
Chris Dollin <ch**********@h p.comwrote:
>Is it true that header files always have only "function declaration"
and not definition?
>But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).
There are also other reasonable uses of #include that are not "header
files", such as compilation units with identical parts, or ones
generated in parts.

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 8 '06 #6
Richard Tobin wrote:
In article <ei*********@ma latesta.hpl.hp. com>,
Chris Dollin <ch**********@h p.comwrote:
>>Is it true that header files always have only "function declaration"
and not definition?
>>But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).

There are also other reasonable uses of #include that are not "header
files", such as compilation units with identical parts, or ones
generated in parts.
I'll grant that.

--
Chris ".enable proofreading" Dollin
"Who do you serve, and who do you trust?" /Crusade/

Nov 9 '06 #7
ben
Thanks to all for ur answers.

--
Ben
Chris Dollin wrote:
Richard Tobin wrote:
In article <ei*********@ma latesta.hpl.hp. com>,
Chris Dollin <ch**********@h p.comwrote:
>Is it true that header files always have only "function declaration"
and not definition?
>But that's generally good practice, except possibly for static inline
functions (if you're using C99 or deliberately restricting yourself to
C89 implementations with that as an extension).
There are also other reasonable uses of #include that are not "header
files", such as compilation units with identical parts, or ones
generated in parts.

I'll grant that.

--
Chris ".enable proofreading" Dollin
"Who do you serve, and who do you trust?" /Crusade/
Nov 9 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2214
by: Chris Mantoulidis | last post by:
Seperate compilation (that's what it's called, right?) seems to be quite popular, so I decided to get some info about it, and (d'oh) use it... But it's whole structure seems weird to me... Here's what I think of how it is (from what I've read): THE PROJECT +1st header file
21
2585
by: Hattuari | last post by:
I'm learning C++ after having spent several years in the computer industry doing both system administration and engineering. I've written code in Perl, Bash, Pascal, Ada, C, Mathematica (hundreds of lines of OO code, not 1+1), JavaScript, Lisp, and Java, as well as C++. Each of these languages has it's strengths and weaknesses. My...
16
12512
by: matthurne | last post by:
I just started learning C++ on my own...I'm using Accelerated C++. Something it hasn't explained and I keep wondering about is how header files actually work. I suspect it doesn't get into it because it is, as the authors love to say, "implementation specific". If that's the case, how does the compiler commonly handle them? I use Linux and...
11
2738
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do understand the objective. This example may represent an interface in need of a bit of refactoring, but it goes to demonstrate the basic idea as I...
3
3081
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by using header file. i can create a class c1 with f1() in c1.h and include this c1.h in file1.cpp by giving the statement #include "c1.h" tell me that...
11
5562
by: ambika | last post by:
Iam just trying to know "c". And I have a small doubt about these header files. The header files just contain the declaration part...Where is the definition for these declarations written??And how does that get linked to our program when we run it??I would appreciate any helpful info..And I would like to thank you for that in advance -ambika
18
2724
by: John Smith | last post by:
Hi all What does the group think of the practise of including one header file from inside another? I have some legacy code where this has been done, and it creates a dependency on a module (collection of files) which are not required, except for one header file's contents. I'd say 'No, header files should be included in the C source,...
8
2758
by: ginnisharma1 | last post by:
Hi All, I am very new to C language and I got really big assignment in my work.I am wondering if anyone can help me.........I need to port compiler from unix to windows and compiler is written partially in c and partially in fortran. I guess i need to change host specific files to make it working. I wonder if standard header files are...
36
3804
by: zouyongbin | last post by:
Stanley B Lippman in his "C++ Primer" that a definition like this should not appear in a header file: int ix; The inclusion of any of these definitions in two or more files of the same program will result in a linker error complaining about multiple definitions. So this kind of definition should be avoided as much as possible. But as we...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.