Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!LBL.GOV!nagy%warner.hepnet From: nagy%warner.hepnet@LBL.GOV (Frank J. Nagy, VAX Wizard & Guru) Newsgroups: comp.os.vms Subject: RE: 2 C questions Message-ID: <880409111116.20a031e1@LBL.Gov> Date: 9 Apr 88 18:11:16 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 42 > C vs. Fortran speed: Since C variables are automatic (i.e., dynamic) by > default and Fortran variables are static, is it fair to conclude that in > general, a routine in C having the same number of local variables as > a "roughly identical" Fortarn routine will take a bit longer because > the OS must allocate (and deallocate) space for the local variables? > If the C local variables are made static, does this possible performance > advantage disappear? On the VAX there is very little performance lost due to the automatic variables. Assuming the variables are not initialized (in which case they would be essentially same as static variables in terms of performance), then all that is needed is a single instruction: SUBL2 #<# of bytes of auto variables>,SP to bump the stack pointer down to allocate the auto variables. Nothing need be done to deallocate them since the old value of the stack pointer is taken from the call frame by the RET instruction. This automatically "pops" the auto variables, the call frame AND the argument list (when a CALLS instruction is used). With VAX C versus VAX FORTRAN the performance "hit" in doing a routine call is that C (also PASCAL for that matter) uses a CALLS and must PUSH the argument list onto the stack (in reverse order) before the CALLS. (Well, normally the argument is build directly onto the stack and is not PUSHed on from the static location). VAX FORTRAN uses CALLG and a static argument list; but here FORTRAN must overwrite argument values which have changed from the values in the static list - this is true when a subroutine passes arguments it was called with to an inner routine. In these cases, much of the performance advantage of VAX FORTRAN is lost. The other side of the coin is that by building the argument list on the stack at run-time, C and PASCAL automatically support recursion and ASTs in a natural and easy manner. Try that in FORTRAN (I have, I know and that's why I use C these days). = Frank J. Nagy "VAX Guru & Wizard" = Fermilab Research Division EED/Controls = HEPNET: WARNER::NAGY (43198::NAGY) or FNAL::NAGY (43009::NAGY) = BitNet: NAGY@FNAL = USnail: Fermilab POB 500 MS/220 Batavia, IL 60510