user1440717
user1440717

Reputation: 1

PIC chip 16F690

im have problems writing some code on my PIC 16F690.
Im using the PIC C Compiler v4.099.

im trying to pass an int variable as an index to an array like this:

int myArray[2] = {20, 20};
int index = 0;
void myFunction()
{
    int iTest = myArray[index];
}

for some reason this code doesnt work, but when i replace the index in myArray[index]
with a zero like this myArray[0], it works fine

Can anybody explain me what im doing wrong?

Upvotes: -3

Views: 287

Answers (2)

Edwin Buck
Edwin Buck

Reputation: 70939

In embedded programming, typically your C program is part of a greater whole which includes bootstrapping to properly reset the system to run your snipped of compiled C.

Is there any chance that in your programming environment, the name "index" is already reserved for some function, which is then walking past your array's length?

Upvotes: 1

Rob
Rob

Reputation: 15168

"index" is a built-in function on my compiler so that might be why it doesn't "work" in yours.

Upvotes: 1

Related Questions