Multiple function-entries in C?

Daniel R. Levy levy at ttrdc.UUCP
Sat Nov 2 20:52:22 AEST 1985


I have a question that I hope some wizard can answer, with respect to achieving
multiple function-entries in C.  I know this is possible in Fortran; a module
might look like:

      subroutine a(i,j)
      i = j/i
      entry b(i,j)
      i = i + j
      return
      end

and the resulting assembly code would look something like this (please excuse
the length--this is from the f77 compiler with the -Sg options; more text
follows):

	.globl	a_
	.globl	b_
	.align	4
	.text
	.align	4
a_:
	save	&.R1
	addw2	&.F1,%sp
	jmp	.L13
.L14:
	divw3	*0(%ap),*4(%ap),*0(%ap)
	jmp	.L17
	.align	4
b_:
	save	&.R1
	addw2	&.F1,%sp
	jmp	.L16
.L17:
	addw3	*4(%ap),*0(%ap),*0(%ap)
	jmp	.L12
.L12:
.L11:
	ret	&0
	.set	.R1,0
	.set	.FSP1,12
.L13:
	movw	0(%ap),4(%fp)
	movw	4(%ap),8(%fp)
	addw3	&4,%fp,%ap
	.set	.F1,0+.FSP1
	jmp	.L14
.L16:
	movw	0(%ap),4(%fp)
	movw	4(%ap),8(%fp)
	addw3	&4,%fp,%ap
	.set	.F1,0+.FSP1
	jmp	.L17

Now in C, I am aware of the setjmp and longjmp facilities, which allow you
to mark a place in a higher level module and return to it later at will
from a lower level module.  But this seems to be very much the reverse,
where you want to jump into the middle of a lower level module.   This
can conceivably be a great code-saving technique, where two "different"
functions that have a lot in common can share that code without putting
the code in yet another function and increasing the function-calling
overhead.  But I am at a loss as to how to express this in C.  Any hints
or pointers [:-)] will be appreciated....
--
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!ihnp4!ttrdc!levy
-- 
 -------------------------------    Disclaimer:  The views contained herein are
|       dan levy | yvel nad      |  my own and are not at all those of my em-
|         an engihacker @        |  ployer or the administrator of any computer
| at&t computer systems division |  upon which I may hack.
|        skokie, illinois        |
 --------------------------------   Path: ..!ihnp4!ttrdc!levy



More information about the Comp.lang.c mailing list