View unanswered posts | View active topics It is currently Thu Jun 30, 2016 7:13 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
? correct function call by reference ?
Author Message
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
? 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)

Tue Oct 21, 2008 3:17 pm
Rookie

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

The first one is correct.

Tue Oct 21, 2008 6:23 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
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.

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)

Wed Oct 22, 2008 3:18 am
Moderator

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning