Re: Summary: translation units, preprocessing, compiling and linking?
From: Howard (alicebt_at_hotmail.com)
Date: 06/03/04
- Next message: Victor Bazarov: "Re: Random Numbers -- why doesn't this piece of code work?"
- Previous message: Moritz Beller: "Re: Random Numbers -- why doesn't this piece of code work?"
- In reply to: Steven T. Hatton: "Re: Summary: translation units, preprocessing, compiling and linking?"
- Next in thread: JKop: "Re: Summary: translation units, preprocessing, compiling and linking?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 03 Jun 2004 18:01:15 GMT
"Steven T. Hatton" <susudata@setidava.kushan.aa> wrote in message
news:8o-dnSG807b3vyLdRVn-ug@speakeasy.net...
> "Compilation can involve up to four stages: preprocessing, compilation
> proper, assembly and linking, always in that order. The first three
stages
> apply to an individual source file, and end by producing an object file;
> linking combines all the object files (those newly compiled, and those
> specified as input) into an executable file.
>
> "For any given input file, the file name suffix determines what kind of
> compilation is done:
>
> file.c
> C source code which must be preprocessed.
>
> file.i
> C source code which should not be preprocessed.
>
> file.ii
> C++ source code which should not be preprocessed.
>
> file.m
> Objective-C source code. Note that you must link with the
> library libobjc.a to make an Objective-C program work.
>
> file.mi
> Objective-C source code which should not be preprocessed.
>
> file.h
> C header file (not to be compiled or linked).
> file.cc
> file.cp
> file.cxx
> file.cpp
> file.c++
> file.C
> C++ source code which must be preprocessed. Note that in .cxx, the last
two
> letters must both be literally x. Likewise, .C refers to a literal
capital
> C."
>
> So I type in 'gcc -ofoo main.cc' and get a bunch of errors, then type `g++
> -ofoo main.cc' and the same code comepiles. Go figure!
This looks like you've quoted a particular implementation's documentation,
not the standard. If I recall correctly, there is nothing in the standard
that specifies that a file have a particular extension, or any extension at
all, for that matter. As far as I know, you can call your main source file
"Bob", and have it include a "header" file called "Carol". What makes
something a source file is if you instruct your compiler to compile it.
What makes it a header file is if you include it from one or more source
files, but don't directly compile it. (Actually, there is no such thing in
the standard as a "header file", if I recall. The term is used to specify
an include file that contains the declarations for the classes and/or
functions implemented in the source file.) Exactly how you instruct your
compiler to compile a file is up to the compiler vendor. Obviously, some
vendors chose to recognize specific file extensions as compileable (source)
files. (Possibly to make it easier to compile all source files in a given
directory?) Likewise, extensions like .a and .o are totally arbitrary,
although they tend to follow common practice.
-Howard
"All programmers write perfect code.
...All other programmers write crap."
"I'm never wrong.
I thought I was wrong once,
but I was mistaken."
- Next message: Victor Bazarov: "Re: Random Numbers -- why doesn't this piece of code work?"
- Previous message: Moritz Beller: "Re: Random Numbers -- why doesn't this piece of code work?"
- In reply to: Steven T. Hatton: "Re: Summary: translation units, preprocessing, compiling and linking?"
- Next in thread: JKop: "Re: Summary: translation units, preprocessing, compiling and linking?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|