View previous topic :: View next topic |
Author |
Message |
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
pointer to multi-dim array question |
Posted: Fri Sep 11, 2015 11:18 am |
|
|
CCS Ver 5.048
My K&R book is at home and I fully intend to review it tonight, but in the meantime can someone answer a question for me?
I have 4 arrays and I want to do the same process on each of them, so I want to define a pointer that can point to whichever array I want.
I checked on the internet and thought the correct syntax would be
Code: |
unsigned int16 (*MyArray)[12][4];
|
but the compiler throws an error on that line. Is that incorrect C syntax? What I THINK I'm saying is, create MyArray to be a pointer to a 12x4 array of uint16's. If I leave off the () I believe it will create an array of pointers instead of uint16's.
If I recall K&R, you have to at least tell the compiler the first dimension so it can calc offsets correctly. My problem is telling the compiler the dimensions of the array. It seems to just get mad at me.
Code: |
// my arrays are multi-dimensional
unsigned int16 FirstArray[12][4];
unsigned int16 SecondArray[12][4];
unsigned int16 ThirdArray[12][4];
// create a 'universal' pointer
unsigned int16 (*MyArray)[12][4]; // compliler msg *** Error 48 "B891.c" Line 668(24,25): Expecting a (
// ultimately, I am wanting to copy the address to my generic pointer and do amazing things with it.
MyArray = ThirdArray;
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Sep 12, 2015 10:35 am |
|
|
I attempted to solve your problem but was not able to come up with
a work-around. I think you should report it to CCS. There is the risk,
however, that if they try to implement it, they will break something else.
Vs. 5.048 seems to be running pretty well. Do we want to break it ? |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1349
|
|
Posted: Sun Sep 13, 2015 10:41 am |
|
|
For a workaround, wouldn't a triple pointer work:
Code: |
unsigned int16 ***MyArray;
|
Code: |
MyArray = FirstArray;
*MyArray[0][0] = 23;
|
|
|
|
pmuldoon
Joined: 26 Sep 2003 Posts: 218 Location: Northern Indiana
|
|
Posted: Mon Sep 14, 2015 5:39 am |
|
|
PCM programmer wrote: | I attempted to solve your problem but was not able to come up with
a work-around. I think you should report it to CCS. There is the risk,
however, that if they try to implement it, they will break something else.
Vs. 5.048 seems to be running pretty well. Do we want to break it ? |
I certainly don't want to be the guy that breaks the compiler.
I was mostly trying to determine if I was doing something wrong or if the compiler had some kind of limitation.
I've done a workaround by passing the array ptr thru a function parm that did compile and seemed to work:
Code: |
void SendReading(unsigned int Channel,unsigned int16 MyArray[12][4])
{
.
.
.
}
|
Then I pass the appropriate array when I call the function:
Code: |
SendReading(3,FirstArray);
|
That DOES seem to work, but is it an okay way to do it? |
|
|
|