Prepending _ in C external names necessary?

Tim Radzykewycz radzy at calma.UUCP
Fri Dec 6 04:40:59 AEST 1985


In article <9113 at ritcv.UUCP> spw2562 at ritcv.UUCP (Fishhook) writes:
>I don't know if this is tru for all systems, but one system I worked
>on passed parameters to system calls using specific registers.  Paremeters
>to C functions are passed on the stack.  Therefore, for the compiler to
>call user functions and system calls, it has to know what all the system
>calls are.

Many flavors of UNIX, and at least some other OS's I know of use
special code to make system calls.  Generally, this is something
like "trap", "emt", "sintr" or the equivalent.  These are treated
similar to interrupts, in that they cause the state of the processor
to change from user to system, change from user stack to system
stack, and several other things.  With this kind of architecture,
the system calls really do have parameters passed on the stack,
and the OS grabs the info off of the user stack whenever there is
a system call.  This eliminates the need for having a separate pair
of subroutines, one of which massages the locations of parameters
for the other.

>The system I worked on treated all system calls as function calls and
>had function stubs which moved the stack parameters to the proper registers
>then performed the actual system call.  Naturally, these stubs are written
>in assembly.  For this to be possible, the system call has to be different
>from the function call.  Answer?  Prepend every C function call with an
>underline, prepend all the function stubs with an underline, DON'T prepend
>system calls.  Therefore,

>[examples given]

>Without underscore prepending this would not be possible.

The only system I'm familiar with which has this kind of setup is XINU,
although I'm certain there are others (perhaps OS-9?).  The real point
of this followup, though, is that it is still possible to get the
functionality that Mr. Wall specified, simply by reversing the scheme:
thus, the massaging routine would be named "write", and the underlying
system call would be named "_write" (or something similar).  This
does have the disadvantage of making it possible for someone to write
a subroutine whose name conflicts with a system call, but it might
be possible to set the name to something which is illegal in C, such
as "$write", instead.  Of course, that's assuming that the '$' character
*is* legal for the assembler.

No, underscore prepending isn't the only answer, but it seems to be
the most common.  I don't see why it's such a big deal.
-- 
Tim (radzy) Radzykewycz, The Incredible Radical Cabbage
	calma!radzy at ucbvax.ARPA
	{ucbvax,sun,csd-gould}!calma!radzy



More information about the Comp.unix.wizards mailing list