Table Element passed to Pointer Table

I’m trying to recreate this line from the PAC Control User Guide, Page 346, on Pointer Tables.

ptTable6[2] = &stStrT1[0];

I keep getting an error when compiling ’ Error on line XX: syntax error at or near “[” ’

Really, I want a pointer variable to point to an element in a float table (which also doesn’t want to work) but I thought at least I could get the book example to work.

Any advise on how to get pointers to reference a table element would be great!

I think that is a mistake in the User Guide (@GrayChurch.Opto22) . I don’t think you can create a pointer to an element of a table, only to the entire table itself.

ptTable6[2] = &stStrT1;
pTable = ptTable6[2];
sValue = *pTable[0];

Thanks Philip, that’s what I suspected. I was looking to make some elaborate indexing more readable.

So instead of something like using the following over and over:
stProfile_Variables[nIndex * 5 + 15] = stProfile_Variables[nIndex * 5 + 15] - stProfile_Variables[nIndex * 5 + 14] ;

I could use:
pSetPoint_1 = &stProfile_Variables[nIndex * 5 + 15];
pProcessValue_1 = &stProfile_Variables[nIndex * 5 + 14];
*pSetPoint_1 = *pSetPoint_1 - *pProcessValue_1;

Which is much more readable, I’ll just make sure and document things very thoroughly.

Is stProfile_Variables a string table? If so, there are other issues with your code. You can’t subtract a string from a string.

Can you explain what you are attempting to do?

should be a float table, just a typo

Not sure how much it improves readability, but you could just use a regular float variable:

fSetPoint_1 = ftProfile_Variables[nIndex * 5 + 15];
fProcessValue_1 = ftProfile_Variables[nIndex * 5 + 14];
fSetPoint_1 = fSetPoint_1 - fProcessValue_1;
ftProfile_Variables[nIndex * 5 + 15] = fSetPoint_1;

1 Like