Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site gitpyr.UUCP Path: utzoo!watmath!clyde!burl!ulysses!gatech!gitpyr!jkr From: jkr@gitpyr.UUCP (John Kenneth Riviere) Newsgroups: net.micro.pc,net.lang.pascal Subject: Re: local variable in assembly routine to be call from TURBO PASCAL Message-ID: <1090@gitpyr.UUCP> Date: Mon, 25-Nov-85 22:46:49 EST Article-I.D.: gitpyr.1090 Posted: Mon Nov 25 22:46:49 1985 Date-Received: Tue, 26-Nov-85 21:00:13 EST References: <1165@princeton.UUCP> <1062@gitpyr.UUCP> Reply-To: jkr@gitpyr.UUCP (John Kenneth Riviere) Distribution: net Organization: Georgia Institute of Technology Lines: 33 Xref: watmath net.micro.pc:6011 net.lang.pascal:396 Summary: Use typed constants. In article <1165@princeton.UUCP> wei@princeton.UUCP (P Wei) writes: > >My final goal is to set a 'static local variable' (like in C) such that on >second entry into this routine I can still get the value of variable set last >time. From the TURBO reference manual, the local variable is stored in stack >segment. So I think the above routine is not going to work. Can anyone tell >me a workable procedure ? >Thanks. >HP Wei (wei@princeton) I have not responded earlier in hopes that someone else will point this out for me, but as I have not seen this solution suggested yet I guess I will add my $.02. It is not obvious from the Turbo Pascal manual unless you read it carefully, but it is possible to declare what amounts to a static local variable within a procedure or function by declaring it as a typed constant. These are the initialized constants that Turbo allows and the space for them is allocated in the code segment which will not change from one recursion to another (except as the procedure's code changes it). They are not really constants since it is possible to change their values, but they seem to be frequently overlooked since their declaration indicates that they are constants. I haven't tried using them with inline code, but in Chapter 20 of my Turbo 3.0 manual it specifically mentions typed constants as being accessible through the CS register when doing inline code. Note that if the procedure in question is being reloaded from an overlay file then the initial value will be reloaded along with the rest of the code so it is not static in this case, but other- wise it should be OK. Hope this helps. -- J. Kenneth Riviere (JoKeR) Georgia Institute of Technology, Atlanta Georgia, 30332 ...!{akgua,allegra,amd,hplabs,ihnp4,seismo,ut-ngp}!gatech!gitpyr!jkr