C is NOT a portable assembler (was: want to know)

Badger BA 64810 bbadger at x102c.harris-atd.com
Fri Aug 25 05:00:41 AEST 1989


In article <2659 at cbnewsc.ATT.COM> nevin1 at ihlpb.ATT.COM (nevin.j.liber,55528,ih,4f410,312 979 4751) writes:
>In article <1496 at l.cc.purdue.edu> cik at l.cc.purdue.edu (Herman Rubin) writes:
>
>>No, the question is not a JOKE.  It is a stupidity in UNIX which causes the
>>problem.  I have used other systems in which the main program could have
>>any name whatever, and even in which the entry need not be to a main program,
>>while a main program is present.  I have even used it.
>
>It has finally dawned on me on what Herman Rubin thinks C is.  Now I
>know why stuff like entry points and hardware registers and NAND
>gates bother him.  He must have heard the phrase "C is kind of a
>portable assembler".  This phrase is a misnomer!
>
I don't speak for Mr. Rubin, but it seems to me you are leading this
discussion away from the topic.

The question here was whether ``main()'' is an attractive feature of
the C language.  That is, why can't all routines have a programmer-chosen
name?  This is an issue in expressiveness, and questions an apparently 
gratuitous irregularity in the language.  

The reference to entry points had to do with how the current
implementations of C manage to call the first routine.  

The starting address specified in ``ld -e epsym'' (that is, the entrypoint 
symbol) isn't the same thing as the address as the first routine called.
     -e epsym
          Set the default entry point address for the output file
          to be that of the symbol epsym.

     -    When the link editor is called through cc(1), a startup
          routine is linked with the user's program. This routine
          calls exit( ) (see exit(2)) after execution of the main
          program. If the user calls the link editor directly,
          then the user must insure that the program always calls
          exit( ) rather than falling through the end of the
          entry routine.

All this talk about implementation is to rebut the contention that ``main()''
is somehow critical to the C language definition by providing explicit 
implementation details to how you might build a program.  We don't
want to change the name of ``main()'' so that we can perform low-level 
assembler-like symbol definitions, we're telling you how to use the 
linkage machinery to remove a restriction in C.

In most cases all the language and system-dependent start-up and
shutdown are encapsulated in ``crt0.o''.  ``main()'' can be, and
probably is, compiled as a _completely_ normal subroutine.
The only thing missing to allow link-time election of a main routine
is a mechanism in ``crt0.o'' to call a specified function.  Somehow 
aliasing ``main'' to the desired symbol seems to be a suitable mechanism.


Bernard A. Badger Jr.	407/984-6385          |``Use the Source, Luke!''
Secure Computer Products                      |``Get a LIFE!''  -- J.H. Conway
Harris GISD, Melbourne, FL  32902             |Buddy, can you paradigm?
Internet: bbadger%x102c at trantor.harris-atd.com|'s/./&&/g' Tom sed expansively.



More information about the Comp.lang.c mailing list