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

Passing array pointer to function

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



Joined: 09 Feb 2007
Posts: 56

View user's profile Send private message

Passing array pointer to function
PostPosted: Mon Mar 02, 2015 10:03 am     Reply with quote

Hello,
I am trying to find a way of passing array pointers to a function.

The following code fails to compile at the "POP R0[0]" line. The compiler (V4.14) complains that the expression does not resolve to a constant.

Any suggestions how to fix the code?

Thanks!

Code:
void Read4ADCs(int16 *R0[], *R1[], *M0[], *M1[])
//** Routine to read 4 x ADCs **
{
#WORD REGE = 0xE44
#WORd REGG = 0xE62

      while (input(ADSTATUS))   //Ensure ADC is busy before proceeding
         {;}
       
      #asm
         CheckG0: BTSS REGG,8      //Check conversion done (g8 is high)
                  goto CheckG0;
         
         NOP
         PUSH 0xE32           //Read REF0 and get ready for REF1
         BSET  REGE,3         //Set E3 (PLD P1) high
         NOP
         NOP
         POP R0[0]
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 10:21 am     Reply with quote

"V4.14" is not a valid version of CCS C, is this V4.140? Is this even CCS C code?

To pass a pointer, whether to an array or not, the syntax would be
void Read4ADCs(int16 *R0, *R1, *M0, *M1). A pointer is a pointer is a pointer: pointers to array elements are indistinguishable from pointers to anything else. Assembler won't index into the array for you, i.e. R0[0] or M1[3], you have to do the calculations. the compiler is telling you that "R0[0]" isn't a constant, such as the "0xE32" you use for the push. it doesn't know how to get the value from the array - you have to do that.

Is this code that you're trying to adapt to do something different to what it was originally written to do? Do you fully understand how it works? Are you aware that almost certainly there's a simpler way to do it using C, and not assembler? It is rare that assembler is needed in CCS C.
nazoa



Joined: 09 Feb 2007
Posts: 56

View user's profile Send private message

PostPosted: Mon Mar 02, 2015 10:54 am     Reply with quote

Thanks for taking the time to reply. I think I understand
where the problem is now.
Yes, the code needs to be in assembly for speed.
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