View unanswered posts | View active topics It is currently Mon Sep 15, 2014 5:35 am






Reply to topic  [ 3 posts ] 
Function with array parameter and class 
Author Message
Rookie

Joined: Sat Mar 14, 2009 3:53 am
Posts: 6
Post Function with array parameter and class
When i declare a function with array parameter and class.
I always get error.
Part of the codes is a as below,

struct typedef
{
int a;
int b;
} data;

data call(int sh[], data temp);

task main()
{
data one;
one.a = 1;
one.b = 1;
int sh[5];
sh[4]....[0] = 1; //short form
one = call(sh, one);
}

data call(int h[], data temp2)
{
............
return temp2;
}

How to declare function with array parameter and class correctly?
Help please.


Sat Mar 14, 2009 4:08 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3218
Location: Rotterdam, The Netherlands
Post Re: Function with array parameter and class
RobotC does not support passing arrays to functions. I suggest you use a struct of some kind. I used the following kludge:

Code:
/**
 * Array of bytes as a struct, this is a work around for RobotC's inability to pass an array to
 * a function.  The int has to be there or it won't work.
 */
typedef struct {
  byte arr[MAX_ARR_SIZE];
  int stupid_work_around_for_array_bug;
} tByteArray;

/**
 * Array of ints as a struct, this is a work around for RobotC's inability to pass an array to
 * a function.  The byte has to be there or it won't work.
 */
typedef struct {
  int arr[MAX_ARR_SIZE];
  byte arrays_in_robotc_are_bugged_as_hell;
} tIntArray;


This seems to work. Not sure if returning a struct from a function works. I wouldn't bet on it.

Regards,
Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Mar 14, 2009 5:58 am
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Function with array parameter and class
... and as far as I know, in ROBOTC this aint working never:
Code:
data call(int h[], data temp2)


you have to fill in the size of h[], ROBOTC didn't work when I once tried to do sth like this.

ROBOTC is not C, its hardly "not quite C" and - as Mightor said - bugged like hell... :breakcomputer:

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Sat Mar 14, 2009 9:04 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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 post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.