cottrell@NBS-VMS.ARPA (COTTRELL, JAMES) (11/04/85)
/* > 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: [Fortran ASM deleted. Boy was it UGLY!] > But I am at a loss as to how to express this in C. Any hints > or pointers [:-)] will be appreciated.... You cannot do this directly, but you can achieve the same effect by specifying an extra arg specifying which entry you want. Then use it in a switch statement to select the proper processing. #define A 0 #define B 1 func(which,i,j) int which, i, j; { switch (which) case A: i = j / i; case B: i += j; /* use C notation */ } } When I figured this out I no longer craved multiple entry points, altho I don't condemn them either. Information can be passed by way of the PC as well as any general register, altho it seems more prone to abuse. jim cottrell@nbs */ ------
mikes@3comvax.UUCP (Mike Shannon) (11/07/85)
Regarding how to do: > > subroutine a(i,j) > > i = j/i > > entry b(i,j) > > i = i + j > > return > > end > > But I am at a loss as to how to express this in C. Any hints > > or pointers [:-)] will be appreciated.... > > You cannot do this directly, but you can achieve the same effect by > specifying an extra arg specifying which entry you want. Then use it > in a switch statement to select the proper processing. I don't buy it; make 'b' a procedure, which can be called by 'a' or called directly by someone else. -- Michael Shannon {ihnp4,hplabs}!oliveb!3comvax!mikes