indexing has at least one undefined operand

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The simulator is telling me this as I try to examine some code that goes astray. I expect it means I have something screwed up. But what?

It says SetPosition[1] is bogus. See the image.

The code says:

volatile int SlewTo[4] = {0,0,0,0} ;
volatile int SlewRate[4] = {0,0,0,0};
volatile int SetPosition[4] = {0,0,0,0} ;

int main(void)
{
	SlewTo[1] = 99 ;
	SlewRate[1] = 20 ;
	SetPosition[1] = 0 ;
    while(1)
    {
        int s = 1;
		if (SlewRate[s] != 0)
		{
			int w = SetPosition[s];		//994
			int nw = w + SlewRate[s] ;	//989
			int sw = nw ;				//989
			if (( SlewRate[s] < 0 ) || (w>SlewTo[s]) || (nw < SlewTo[s]))
			{
				sw = SlewTo[s];
				SlewRate[s] = 0;
			}
			if ((SlewRate[s] > 0 )|| (w SlewTo[s]))
			{
				sw = SlewTo[s];
				SlewRate[s] = 0;
			}
			SetPosition[s] = sw;
		}
    }
}

This is, of course, a donothing program containing a bit of code that malfunctions out of a non-donothing program.

Perhaps GCC has figured out that it's a donothing program and optimized it all away?

Attachment(s): 

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Imagine you are the C compiler. Now walk that code. You'll find s set to 1 but nothing changes it. So it need never index any [1] element but can access it directly. If you really want the compiler and debugger to behave as if those things are changeable make them volatile.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I know why the code is going astray, but not what it's telling me about SetPosition...

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Changed the erroneous ||s into the intended &&s, and put a for loop like the real program has, and now it behaves as I desired.

Unfortunately, it does not in the real program.

So I rewrote it from scratch using a typedef and an array of the type so I can get SV[s].Location, SV[s].Desitnation and SV[s].Rate. Unfortunately, the real program still exhibits the misbehavior. So I went for a long walk.

If you don't know my whole story, keep your mouth shut.

If you know my whole story, you're an accomplice. Keep your mouth shut. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My guess is that the debugger doesn't know what SetPosition is at the particular position in code. To verify, watch SetPosition without the []

This could be because the line or variable was optimized away, or the compiler did not generate debug info for SetPosition at the current PC location.

Dan