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

i need help with pointer array function parameter

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



Joined: 08 Feb 2011
Posts: 32

View user's profile Send private message

i need help with pointer array function parameter
PostPosted: Sat Jul 05, 2014 6:52 pm     Reply with quote

Hi guys, i need to send an array of bytes to a function that will write it on spi, like this pseudo code:

Code:

int8 function write( int8 *data ) {
  for( idx=0;idx++;idx=sizeof(data) ) {
      spi_write( data[idx] );
  }

  return 0;
}

void main () {
  initialize....
   
  // the array size is not fixed, i need send from 2 to 40 bytes at time, but is array values are hard coded.
  status = write( {0x26,0x01,0x30,0x55} );
}


How can i do that in ccs ? someone can write a sample code?

I will appreciate some help!

thanks...
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jul 05, 2014 9:15 pm     Reply with quote

The simple way is just to define your function with two parameters.
The first one is a pointer to the array. The second one is the array size
in bytes, or the number of bytes that you want to be processed in the
array. In other words, you pass the size along with your array pointer.

Here's how you would call it:
Code:
result = function_write(my_array, sizeof(my_array));


Here's some more. I just did a search and Ttelmah has sample code for
you in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=48285
Ttelmah



Joined: 11 Mar 2010
Posts: 19509

View user's profile Send private message

PostPosted: Sun Jul 06, 2014 12:58 am     Reply with quote

Also, this thread:

<http://www.ccsinfo.com/forum/viewtopic.php?t=52242&highlight=array+sizeof>

Covers why the called function can't know the 'size' of what is passed, without this being also sent.
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