View unanswered posts | View active topics It is currently Sat Nov 22, 2014 12:29 pm






Reply to topic  [ 4 posts ] 
? correct function call by reference ? 
Author Message
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post ? correct function call by reference ?
hi,
currently I'm not quite sure: what is the correct way, to call a function by reference?

my function defintion is e.g.:
Code:
void myFunc(int &value)
{
  value=value/2;
}


now I want to call the function by reference. Which is correct way?
1.:
Code:
int myVar;
myVar=10;
myFunc(myVar);

2.:
Code:
int myVar;
myVar=10;
myFunc(&myVar);

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


Tue Oct 21, 2008 3:17 pm
Profile
Rookie

Joined: Wed Jun 25, 2008 6:07 pm
Posts: 46
Post Re: ? correct function call by reference ?
Ford,

The first one is correct.


Tue Oct 21, 2008 6:23 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: ? correct function call by reference ?
thx,
that's the way I did it so far.
But because of those consistant "nan" errors I slowly began to (falsely) doubt this. :oops:

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


Wed Oct 22, 2008 3:18 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post Re: ? correct function call by reference ?
Since RobotC does not have pointers, they have adopted a C++ style of pass by reference. You only have to declare the & in the function input, and it will automatically dereference everything else for you.

Scott B-)

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Wed Oct 29, 2008 1:43 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 4 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.