Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

static variable inside a procedure ?

573 views
Skip to first unread message

Jan Vermaete

unread,
Feb 8, 2001, 6:12:43 AM2/8/01
to
Hello,

Is it possible to make someting like this:

PROCEDURE SaveTestResults (
CONSTANT FileName : IN string;
CONSTANT F_DataA : IN integer;
CONSTANT F_DataB : IN integer
)
IS
FILE StimuliOut : text OPEN append_mode IS FileName;
VARIABLE Oline : LINE;
CONSTANT StoreValue : positive := 20;
TYPE StoreLine IS RECORD
A : integer;
B : integer;
END RECORD;
TYPE StoreType IS ARRAY (0 TO StoreValue-1) OF StoreLine;
variable store: StoreType;
variable i : natural := 0;
BEGIN
Store(i).A := F_DataA;
Store(i).B := F_DataB;
i := i+1;
if i = StoreValue then
i := 0;
FOR j IN 0 TO StoreValue-1 LOOP
write(oline,Store(j).A, right, 15 );
write(oline,Store(j).B, right, 15 );
END LOOP;
WriteLine(StimuliOut, oline);
END if;
END SaveTestResults;

The problem is that the variables "i" and "store" are not global. So
this code will not work. But how can I make "i" and "store" static so
that they will keep they value.
(The FAQ only give some exemaples with constant and generics)
Thanks,

Jan Vermaete

me...@mench.com

unread,
Feb 8, 2001, 2:09:50 PM2/8/01
to
On Thu, 08 Feb 2001 12:12:43 +0100, Jan Vermaete
<mae...@nospam.rsd.bel.alcatel.be> wrote in article
<3A827F2B...@nospam.rsd.bel.alcatel.be>:

Anything declared within a subprogram is elaborated each time the
subprogram is called, so they do not retain their values between
invocations.

There are two basic approaches to making these variables retain their
values between calls:

1. Declare i and store global to the procedure. (Note that this
approach will limit where you can declare the procedure, so approach 2
might work better for you.)

2. Pass them as inout variable parameters to the procedure.

Hope this helps,

Paul

--
Paul Menchini | "There must have been a time, probably somewhere near
Menchini & Associates | the beginning, when we could have said 'no.'"
www.mench.com | -- from "Rosencrantz and Guildenstern are Dead"

e...@riverside-machines.com.nospam

unread,
Feb 8, 2001, 4:49:46 PM2/8/01
to
On Thu, 08 Feb 2001 12:12:43 +0100, Jan Vermaete
<mae...@nospam.rsd.bel.alcatel.be> wrote:

>The problem is that the variables "i" and "store" are not global. So
>this code will not work. But how can I make "i" and "store" static so
>that they will keep they value.
>(The FAQ only give some exemaples with constant and generics)
>Thanks,
>
>Jan Vermaete

The closest you can get to statics and externals are shared variables,
which will do what you want. However, your code probably wont be
synthesisable. You could also pass signal parameters to your procedure
(or assign to a signal which isn't a parameter - see the FAQ), and use
the signal for storage.

Evan

Mike Treseler

unread,
Feb 8, 2001, 1:34:16 PM2/8/01
to
Jan Vermaete wrote:
>
> Hello,
>
> Is it possible to make someting like this:
>
> PROCEDURE SaveTestResults (
. . .


> The problem is that the variables "i" and "store" are not global. So
> this code will not work. But how can I make "i" and "store" static so
> that they will keep they value.

How about writing:

PROCEDURE GetTestResults (

-- mike.treseler at flukenetworks dot com

0 new messages