View unanswered posts | View active topics It is currently Fri Jul 25, 2014 3:46 am






Reply to topic  [ 5 posts ] 
Passing an array by ref as a function argument 
Author Message
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post Passing an array by ref as a function argument
Hey there,

I am trying the following code:
Code:
void output(byte _out[]) {
   nxtDisplayTextLine(2, "out[0]: %d", _out[0]);
   nxtDisplayTextLine(3, "out[1]: %d", _out[1]);
}

But then I get the following errors:
**Error**:Ummatched left parenthesis '('
**Error**:Expected->')'. Found '['
**Error**:No body declared for procedure
**Error**:Unexpected scanner token-> '['
**Error**:Unexpected scanner token-> ', '
**Error**:Unexpected scanner token-> ')'
*Warning*:Unreferenced function 'output'
**Error**:Undefined variable '_out'. 'short' assumed.

Seems a little odd. I am not keen to use global variables in my program, they leave a nasty taste in my mouth.

How is it done in RobotC? I am using v1.40RC3

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]


Fri Jul 25, 2008 3:35 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post 
I see no difference at all, same errors, different type, meh. This sucks.
I really, really don't want to use global variable to work around this, that would be really terrible.

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]


Fri Jul 25, 2008 4:04 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
(EDIT)
I think you must not pass an array cause this is not a valid variable type, but maybe you define a structure consisting this array and pass this structure as a function parameter.
This is the way I've done this several times before (1.30)

_________________
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)}


Fri Jul 25, 2008 4:07 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3163
Location: Rotterdam, The Netherlands
Post 
ack, ok. I did notice you doing that in your Neural Network program, hehe. Ok, I will use that then. Such a hack, though.

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]


Fri Jul 25, 2008 4:09 pm
Profile WWW
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post 
always look on the bright side of life... Image

_________________
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)}


Fri Jul 25, 2008 4:27 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.