Jump to content
Excelsior Forums
oo

Way to override Error: Control Variable "%s" is threatened here (E158)

Recommended Posts

Hi,

I hope you guys would not mind another question.

I am trying to compile some old code, and I get a number of errors of the form:

* [VERIFICA.MOD 55.11 E147]

* threatened variable is not allowed here

    FOR i2$:=0 TO b-1 DO

* [VERIFICA.MOD 56.49 E158]

* control variable "i2" is threatened here

      IF presrow^.outd[i2] # "-" THEN ab:=TRUE; $i2:=b-1 END;

This means that the compiler does not like the assignment to i2 in the loop where it is the control variable.

My professor who wrote this code told me that when he used the TopSpeed Compiler years ago and this was acceptable then.

So, is there a way to override this error ? because otherwise there are just too many instances of this in the code?

Thank you for your support.

O.O.

Share this post


Link to post
Share on other sites

No, there is no way to supress these errors. A control variable of a FOR statement cannot be changed by assignment or passing as a VAR parameter. It seems, unfortunately, you need to rewrite all such code.

Share this post


Link to post
Share on other sites

Thanks sleepyhead.

So is this standard. If yes, then I might consider rewriting the code. If not then I would try other compilers.

Thanks a lot.

O.O.

Share this post


Link to post
Share on other sites

As I remember, ISO Modula-2 Standard says that a variable that is used as a control variable of FOR statement must be a simple variable, must be a local variable, but not a formal parameter, must not be exported nor imported, must not be threatened in any statement within the statement sequence of the FOR statement or by any procedure in the declarations part of the block containing this FOR statement. (If a control variable is not threatened, no statement other than the FOR statement itself can attempt to alter the control variable.)

Anyway, you can try other compilers to avoid rewriting a lot of code.

Share this post


Link to post
Share on other sites

Thanks sleepyhead for clarifying that this is part of the standard.

I think I might have to rewrite some of my code ? if it is not too complicated. I am thinking of simply declaring an extra variable in these circumstances to do the job. But this may not always work.

I am busy with some other work now. I would get to this in a week or two. I would let you know when I have a few more questions, or when I get this done or give up.

Regards,

O.O.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×