C prepend _: Summary
Dave Lennert
davel at hpda.UUCP
Wed Nov 13 05:05:24 AEST 1985
This is a summary of the replies to my query:
Why prepend an underscore to all C externals symbols?
Thanks to all who replied. Almost all answers said basically the same things.
1) To "hide" mixed language externals.
Because of differences in calling sequences, one may not want, e.g.,
a C library routine to satisfy a reference from a Fortran program.
> From: hpda!ihnp4!research!seki!tac (Tom Cargill)
>
> the motivation is mixed language programming:
> sin from an assembler library
> _sin from a C lib
> _sin_ from an f77 lib
2) To avoid conflicting with assembler predefines or C compiler generated
labels.
This is of concern for C compilers which produce assembler source.
> From: <research!dutoit!dmr> (Dennis Ritchie) (via Chris Torek)
>
> ...both the 11 and the vax assemblers have a single
> symbol table that is primed with all preknown symbols including
> the instructions, and don't use the syntax to distinguish instruction
> values from other symbols. E.g.
> movl clrl,addd
> assembles just fine on the vax; it's a move between two absolute locations.
> From: Doug Gwyn (VLD/VMB) <hpda!ucbcad!brl.arpa!gwyn>
>
> If the assembler reserves "r0" and "r1" to denote registers,
> then the compiler better not send these symbolic names to
> the assembler unmodified. On the other hand, if the assembler
> uses %0 and %1 for register names, and does not understand
> "r0" and "r1" as registers unless explicitly set by the
> programmer, then it is safe for the compiler to pass the
> names straight to the assembler.
> From: hpda!nsc!ihnp4!ukma!david (David Herron, NPR Lover)
>
> For instance, the C compiler generates labels like L0123 for local
> labels (loops). Suppose you were to name a global variable L0123?
> Now you have a conflict.
3) If none of the above are problems on your implementation, then prepending
the underscore can be avoided.
> From: hpda!hplabs!Glacier!decwrl!sun!guy (Guy Harris)
>
> AT&T 3B C implementations don't prepend the underscore.
> From: hpda!ihnp4!cbosgd!bowles (Jeff Bowles)
>
> On the AT&T 68000 cross-compiler, "_" isn't prepended.
4) In cases where there are small limitations on the size of external
names prepending an underscore can be detrimental.
> From: hpda!hplabs!well!micropro!sagan!frank (Frank Whaley)
>
> Regardless of the technical/religious arguments FOR [flame] "that nasty
> little _" [endflame], it and its brethren ('.' from Whitesmith's, etc.)
> have caused me endless grief in porting to/from systems with less than
> 16 significant characters in external names.
BTW, in case anyone is concerned that HP-UX C compilers are going to
suddenly change in how they deal with prepending underscores, don't worry.
I'm working with a C compiler which is for internal use only.
Thanks, again!
Dave Lennert {ucbvax, hplabs}!hpda!davel [UUCP]
Hewlett-Packard - 47UX ihnp4!hpfcla!hpda!davel [UUCP]
19447 Pruneridge Ave. hpda!davel at ucb-vax.ARPA [ARPA]
Cupertino, CA 95014 (408) 447-6325 [AT&T]
More information about the Comp.lang.c
mailing list