CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pointer to multi-dim array question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pmuldoon



Joined: 26 Sep 2003
Posts: 218
Location: Northern Indiana

View user's profile Send private message

pointer to multi-dim array question
PostPosted: Fri Sep 11, 2015 11:18 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Sep 12, 2015 10:35 am     Reply with quote

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: 1358

View user's profile Send private message

PostPosted: Sun Sep 13, 2015 10:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 14, 2015 5:39 am     Reply with quote

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?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group