Re: search path of header files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ranjith kumar wrote:

> 1) when we  write
>                          #include<stdio.h>
> whrer will gcc search for header file stdio.h. ???
> How to know the list of all directories it searches for header files?

You can add -v to your compile flags to see the directory search order.

> 2) I have two .c (1.c and 2.c) files. Both include a(same) header file(1.h).
>      1.h defines a variable say "int a"
>     When we compile 1.c and 2.c to produce a single executable file
> why gcc will not  generate error " int a is decleared two times"?

There is no error because global uninitialized variables use common
storage by default.  This means all all references to the same variable
across multiple files refer to the same storage location.  Try compiling
with -fno-common and you will get an error for multiply defined
variables.

> 3) At waht intermediate representation the contents of a header file
> will be copied to contents of .c file?

Headers aren't different from normal code, they're just extra material
that the compiler reads and parses before reading and parsing your
code.  How they influence the generated output depends on the contents
of the header.  Normally headers contain preprocessor defines for
constants, type definitions, and function prototypes, but no actual
implementation of the library code.  These definitions are incorporated
into the output in the sense that they influence code generation in the
same way as any other C code would, e.g. if you had

  var = open ("foo", O_WRONLY);

Then the value of O_WRONLY from the fcntl.h header would be included in
the output in the sense that the actual function call in the object
would pass the value 1 not the symbolic O_WRONLY.

Some headers do contain more than just defines and types, such as macros
that expand to inline code or actual inline functions, especially common
in C++.  In these cases the code is compiled and copied to the output
just as if it was written as part of the program.

> 4) If GCC is written in C language who will compile it to produce the
> the the executable (compiler itself)?
> I mean ..when GCC is written in C for the first time, how did they
> compile it?? At that time no C compiler was  there.

The first C compiler came out of Bell Labs some time around 1973.  The
first beta release of gcc was in March of 1987.  So, the answer is that
gcc was compiled by an existing C compiler, it was not the first.  A
more interesting question would be "What was that first C compiler at
Bell Labs written in?" which you can read about here:
<http://plan9.bell-labs.com/who/dmr/chist.html>.

Brian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux