Re: Summary: translation units, preprocessing, compiling and linking?

From: Howard (alicebt_at_hotmail.com)
Date: 06/03/04


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."



Relevant Pages

  • Re: Looking for a free basic compiler for DOS
    ... mother of an ide file - and created separate source files for each SUB ... big to compile in one bc step. ... the source for all the SUBS in the same source file. ...
    (comp.lang.basic.misc)
  • Re: disabling parse error in gcc
    ... typedef struct MYSTRUCT{ ... it will compile correctly. ... A header file shall permit multiple inclusion of itself. ... so that a source file containing only TWO #includes of it will compile, ...
    (comp.unix.programmer)
  • Re: A funny yet crazy extreme test on Delphi 7 compiler
    ... The RAM is 1G. ... A project with a major source file names TestCase.pas. ... Delphi can compile crazy functions with 999 parameters. ...
    (borland.public.delphi.non-technical)
  • A funny yet crazy extreme test on Delphi 7 compiler
    ... See how Delphi compiles very huge source file! ... I use the command line tool dcc32 to ... A project with a major source file names TestCase.pas. ... Delphi can compile crazy functions with 999 parameters. ...
    (borland.public.delphi.non-technical)
  • Re: automatically remove unused #includes from C source?
    ... compile error, then the tool cannot assume that file1.h is a -necessary- ... I don't mechanically automate the code change and test process. ... by source file) and check to see whether ... Once you get beyond standard C into POSIX or system dependancies, ...
    (comp.lang.c)