473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

header file in C

hi all,
I just want to know that whether the C header files( like stdio.h,etc

which the compiler provides) just contains the function declarations
or they also contain some additionalinformation like where to look in

the memory for the defintions of the standard functions like

scanf(char*c,...)).

Also,if there is no information about the location of the memory where
the definitions of the standard functions is present,then can we just

declare the function which we want to use,ourselves,and then don't

include the required header file/s.

Also,can you please tell me the steps in brief through which a typical

complier passes the source file so as to generate the final executable

file.

Also,can you please tell me that why an executable file made in Windows

operating system is not recognised by the Linux operating System and

vice-versa.

Thanks in advance,
Candice.
Nov 14 '05 #1
6 1719
candy <ca********@yahoo.com> scribbled the following:
hi all,
I just want to know that whether the C header files( like stdio.h,etc which the compiler provides) just contains the function declarations
That's right, except that they may also contain type declarations and
#defines.
or they also contain some additionalinformation like where to look in the memory for the defintions of the standard functions like scanf(char*c,...)).
No. The C language does not define any such facility.
Also,if there is no information about the location of the memory where
the definitions of the standard functions is present,then can we just declare the function which we want to use,ourselves,and then don't include the required header file/s.
That is correct. All the compiler and linker care about is getting the
needed declarations correctly. They don't care where they come from.
Also,can you please tell me the steps in brief through which a typical complier passes the source file so as to generate the final executable file.
This is too advanced a topic to cover briefly here.
Also,can you please tell me that why an executable file made in Windows operating system is not recognised by the Linux operating System and vice-versa.


Because they use different object code models.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"War! Huh! Good God, y'all! What is it good for? We asked Mayor Quimby."
- Kent Brockman
Nov 14 '05 #2
"candy" <ca********@yahoo.com> wrote in message
news:f4**************************@posting.google.c om...
hi all,
I just want to know that whether the C header files( like stdio.h,etc

which the compiler provides) just contains the function declarations
or they also contain some additionalinformation like where to look in

the memory for the defintions of the standard functions like

scanf(char*c,...)).

Also,if there is no information about the location of the memory where
the definitions of the standard functions is present,then can we just

declare the function which we want to use,ourselves,and then don't

include the required header file/s.

Also,can you please tell me the steps in brief through which a typical

complier passes the source file so as to generate the final executable

file.

Also,can you please tell me that why an executable file made in Windows

operating system is not recognised by the Linux operating System and

vice-versa.

Go to a near bookstore or library and shout for "Compiler Principles, Tool
and Techniques" By Aho, Sethi and Ullman.

--
ISA
Nov 14 '05 #3
Joona I Palaste wrote:
candy <ca********@yahoo.com> scribbled the following:
hi all,
I just want to know that whether the C header files( like stdio.h,etc
which the compiler provides) just contains the function declarations


That's right, except that they may also contain type declarations and
#defines.
or they also contain some additionalinformation like where to look in
the memory for the defintions of the standard functions like
scanf(char*c,...)).


No. The C language does not define any such facility.


Joona is correct when he says the C language as such
has no way to place a particular function at a particular
memory location. However, each implementation of C uses
some amount of "implementation magic" outside the realm of
C itself, and it is at least conceivable that some "magic"
in some implementation might locate its library functions
this way. It would certainly be an unusual approach, but
it's within the realm of possibility. Systems have used
things like "jump tables" or "branch vectors" before, and
perhaps some might still use the technique for C.
Also,if there is no information about the location of the memory where
the definitions of the standard functions is present,then can we just
declare the function which we want to use,ourselves,and then don't
include the required header file/s.


That is correct. All the compiler and linker care about is getting the
needed declarations correctly. They don't care where they come from.


Joona is right again, but some library functions cannot
be declared "free-hand" because there's no way to write their
prototypes without using the contents of the relevant headers.
Take fprintf(), for example: you could write

int fprintf(FILE*, const char*, ...);

easily enough, but you need to have `FILE' declared before
you can do this. The *only* correct way to declare `FILE'
is to include <stdio.h> (because the details of `FILE' vary
from one implementation to another), and since <stdio.h> also
declares fprintf() there's little reason to add your own,
redundant declaration.

Another example: you could write

size_t strlen(const char*);

but where is `size_t' declared? It turns out that many of
the standard header files declare `size_t', and that you could
in fact obtain its declaration by including <stdio.h> or
<stddef.h> or a few others, without including <string.h>.
But the fact that something *can* be done doesn't mean that
it *should* be done; in this case it doesn't even save you
any keystrokes to write a "free-hand" declaration.

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

Nov 14 '05 #4

"candy" <ca********@yahoo.com> wrote

I just want to know that whether the C header files( like stdio.h,etc
which the compiler provides) just contains the function declarations
or they also contain some additionalinformation like where to look in
the memory for the defintions of the standard functions like
If you look at a standard header file by opening it in an editor, you'll
probably find something that looks superficially like gibberish, but when
you examine it closely is a regular C header.
However not all implementations are like this. The compiler isn't required
to have standard headers as actual files.
As for "finding the function in memory", all library or object file
functions need to be located somehow. The standard libary is no different.
scanf(char*c,...)).

Also,if there is no information about the location of the memory where
the definitions of the standard functions is present,then can we just
declare the function which we want to use,ourselves,and then don't
include the required header file/s.
This will probably work, and language lawyers will be able to tell you
whether or not behaviour is defined. However for practical purposes we never
do this. If scanf() is available then stdio.h will also be available, and so
is always included.
Also,can you please tell me the steps in brief through which a typical
complier passes the source file so as to generate the final executable
file.
It first runs the C preprocessor on the file. Then it compiles all the
function definitions to an intermediate format, known as object code, then
it invokes the linker to join the object files and library files into an
executable.
Also,can you please tell me that why an executable file made in Windows
operating system is not recognised by the Linux operating System and
vice-versa.

Through wickedness. The processors are the same, and so the machine code is
basically identical. However the operating system writers have decided to
make the minor loading and initialisation code incompatible, so programs
won't run on each other's platforms and lawsuits / competition is avoided.
Nov 14 '05 #5
bd
Joona I Palaste wrote:
candy <ca********@yahoo.com> scribbled the following:
hi all,
I just want to know that whether the C header files( like stdio.h,etc

which the compiler provides) just contains the function declarations


That's right, except that they may also contain type declarations and
#defines.
or they also contain some additionalinformation like where to look in

the memory for the defintions of the standard functions like

scanf(char*c,...)).


No. The C language does not define any such facility.


Why can't an implementation use some sort of implementation-specific
extension in its headers? Heck, glibc has inline assembly code in some of
its headers.

Nov 14 '05 #6
On Mon, 18 Oct 2004 20:08:44 -0400
bd <bd*****@gmail.com> wrote:
Joona I Palaste wrote:
candy <ca********@yahoo.com> scribbled the following:
hi all,
I just want to know that whether the C header files( like
stdio.h,etc

which the compiler provides) just contains the function
declarations


That's right, except that they may also contain type declarations
and#defines.
or they also contain some additionalinformation like where to look
in the memory for the defintions of the standard functions like

scanf(char*c,...)).


No. The C language does not define any such facility.


Why can't an implementation use some sort of implementation-specific
extension in its headers? Heck, glibc has inline assembly code in some
of its headers.


It can define such an extension, however you are allowed to provide the
function prototypes yourself for the functions (not recommended and in
at least some cases you still need to include headers to get the
relevant types) or in some cases it is valid to use the function without
a prototype in scope at all, so the system must cope if any such fancy
facilities have not been used. Therefor I can't think that an extension
specifying where to find the functions would be of much help to the
implementation.

The fact the implementation could use inline functions and inline
assembler in the headers when they are included (whilst providing some
other mechanism for when they are not included) is just another argument
for including the relevant headers rather than providing the prototype
yourself.
--
Flash Gordon
Sometimes I think shooting would be far too good for some people.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #7

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

Similar topics

3
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... ...
31
by: Steven T. Hatton | last post by:
If a header is not necessarily a source file, and the sequences delimited by < and > in header names aren't necessarily valid source file names, what exactly is a header? -- p->m == (*p).m == p.m...
16
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...
11
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...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
4
by: Andrew Ward | last post by:
Hi All, I was wondering if it is possible to use precompiled headers without having to include a <stdafx.h> or whatever in every source file. My problem is that I have a project that makes heavy...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
16
by: wdh3rd | last post by:
Hi everyone. I'm new to C and I have a few questions: I am making files for permutations and combinations. Files to be made are perm.c, perm.h, combo.c, and combo.h. Since both combinations...
1
by: Shalako | last post by:
I check my error log and see these entries: malformed header from script. Bad header= Missing gauge reports are ind: padata.pl /perl/pema/padata.pl did not send an HTTP header malformed...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.