[TUHS] why the leading under score added to function names?

Random832 random832 at fastmail.us
Sun Feb 26 04:45:23 AEST 2012

On 2/22/2012 11:30 PM, Greg 'groggy' Lehey wrote:
> On Thursday, 23 February 2012 at  8:22:17 +1100, Dave Horsfall wrote:
>> On Wed, 22 Feb 2012, arnold at skeeve.com wrote:
>>> 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!
>> When it comes to Windoze, nothing surprises me any more.  Unix has
>> evolved over the years, but Windoze was spat out and hatched.
> I'm no friend of Microsoft either, but gcc isn't exactly Microsoft.
> What Arnold mentions here is Unix history in action.
Yes and no. IIRC, gcc doesn't do that on, for example, Linux ELF. it's 
done on windows, I assume, in deference to the windows 32-bit ABI for 
cdecl calling convention functions.

Now, as far as where windows gets that from (just because something 
evolved within one company doesn't mean it didn't evolve), supposedly 
early versions of Microsoft C (pre-ANSI) were very conservative in terms 
of adhering to the "standard" set by Unix C and K&R - this could have 
extended to the prepending of underscores. For instance, this is, 
according to Raymond Chen, why they added WinMain rather than extending 
main (they didn't know if extensions to main would be allowed). I would 
also guess it's why MSVC stdio is implemented on top of an imitation of 
Unix system calls which is in turn implemented on top of DOS/windows; 
and why MSVC time_t is defined as seconds since 1970. There are comments 
in the code referring to XENIX in various places relating to I/O and 
timestamps, so it's possible that MSVC's C library was indeed, to some 
small degree, based on Unix.

More information about the TUHS mailing list