The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] why the leading under score added to function names?
@ 2012-02-20 20:52 arnold
  2012-02-20 23:21 ` Dave Horsfall
  0 siblings, 1 reply; 17+ messages in thread
From: arnold @ 2012-02-20 20:52 UTC (permalink / raw)


Hi All.

Recently at work I helped someone figure out that when working with ld,
the name of a function "foo" gets turned into "_foo" by the compiler.
(It took this old-timer 15 minutes to solve a problem he had been working
on for two days!)

I'm pretty sure this dates back to PDP-11 days.  I'm wondering "why?".
Why did the C compiler prepend an underscore to function names?

Thanks,

Arnold



^ permalink raw reply	[flat|nested] 17+ messages in thread
* [TUHS] why the leading under score added to function names?
@ 2012-02-22 19:17 arnold
  2012-02-22 21:22 ` Dave Horsfall
  0 siblings, 1 reply; 17+ messages in thread
From: arnold @ 2012-02-22 19:17 UTC (permalink / raw)


Hi All.

This is interesting. It shows that (apparently) early on, assembler was
viewed as the primary programming language.

It also shows the consequences a small, apparently local decision can have:
here we are 40+ years later and GCC on Windows is still preprending
underscores to function names!

In 15 minutes I helped the guy at work solve a problem he'd been working
on for two days!

Thanks everyone,

Arnold

> From: Brantley Coile <brantley at coraid.com>
> To: Dave Horsfall <dave at horsfall.org>
> Date: Mon, 20 Feb 2012 18:34:26 -0600
> Cc: The Eunuchs Hysterical Society <tuhs at tuhs.org>
> Subject: Re: [TUHS] why the leading under score added to function names?
>
> correct.  we could link to assembler code with _entry points and not
i> worry about symbol collisions in the rest of the code. 
>
> iPhone email
>
> On Feb 20, 2012, at 6:23 PM, "Dave Horsfall" <dave at horsfall.org> wrote:
>
> > On Mon, 20 Feb 2012, arnold at skeeve.com wrote:
> > 
> > [...]
> > 
> >> I'm pretty sure this dates back to PDP-11 days.  I'm wondering "why?".
> >> Why did the C compiler prepend an underscore to function names?
> > 
> > Sure was the PDP-11 :-)  I vaguely recall that it was to make sure that
> > user functions did not conflict with predefined assembler functions, as
> > that would be a pain to diagnose (much like having swap overlap root).
> > 
> > -- Dave



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-02-27  1:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-20 20:52 [TUHS] why the leading under score added to function names? arnold
2012-02-20 23:21 ` Dave Horsfall
2012-02-21  0:34   ` Brantley Coile
2012-02-21  2:50     ` Warner Losh
2012-02-21  3:33       ` John Cowan
2012-02-21  3:41       ` Steve Nickolas
2012-02-21 18:18       ` ron
2012-02-22 19:17 arnold
2012-02-22 21:22 ` Dave Horsfall
2012-02-22 22:47   ` A. P. Garcia
2012-02-23  4:30   ` Greg 'groggy' Lehey
2012-02-25 18:45     ` Random832
2012-02-25 19:24       ` Steve Nickolas
2012-02-25 20:39       ` John Cowan
2012-02-25 22:15         ` Random832
2012-02-26 13:28           ` Ronald Natalie
2012-02-27  1:30             ` random832

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).