Go to Post It's a FIRST thing. You gots to understand. - Koko Ed [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-05-2004, 09:27 AM
cibressus53's Avatar
cibressus53 cibressus53 is offline
Registered User
#1397
 
Join Date: Oct 2004
Location: ajax
Posts: 14
cibressus53 is on a distinguished road
Can't use pointers nor refrences.

Has anyone had any sucess with using pointers or refrences? I thought MLAB was C '89 compleient, I thought pointers atleast were in the orignal C "release"
__________________
EMAIL: TERRYnospamP AHT MELDSTARspammenot DAWT COM
  #2   Spotlight this post!  
Unread 11-05-2004, 09:50 AM
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Can't use pointers nor refrences.

Pointers worked fine for me, once I got the hang of the syntax. I don't often use C, and I find it very nonintuitive.
  #3   Spotlight this post!  
Unread 11-05-2004, 12:04 PM
Mark McLeod's Avatar
Mark McLeod Mark McLeod is online now
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,700
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: Can't use pointers nor refrences.

Quote:
Originally Posted by cibressus53
Has anyone had any sucess with using pointers or refrences?
I also use pointers without any problems, but I'm an old C programmer.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
  #4   Spotlight this post!  
Unread 11-05-2004, 12:31 PM
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: Can't use pointers nor refrences.

Quote:
Originally Posted by cibressus53
Has anyone had any sucess with using pointers or refrences? I thought MLAB was C '89 compleient, I thought pointers atleast were in the orignal C "release"
Pointers work just fine. Here's a simple example from the default code (in user_routines.c):
Code:
/*******************************************************************************
* FUNCTION NAME: Limit_Switch_Max
* PURPOSE:       Sets a PWM value to neutral (127) if it exceeds 127 and the
*                limit switch is on.
* CALLED FROM:   this file
* ARGUMENTS:     
*     Argument       Type             IO   Description
*     --------       -------------    --   -----------
*     switch_state   unsigned char    I    limit switch state
*     *input_value   pointer           O   points to PWM byte value to be limited
* RETURNS:       void
*******************************************************************************/
void Limit_Switch_Max(unsigned char switch_state, unsigned char *input_value)
{
  if (switch_state == CLOSED)
  { 
    if(*input_value > 127)
      *input_value = 127;
  }
}
"unsigned char *input_value" says that "input value" is a pointer to an "unsigned char" type variable.

"*input_value > 127" and "*input_value = 127" are references to the value stored where the pointer... uh... points.

Later on in the same source file, you can find examples of how this function is called:
Code:
  Limit_Switch_Max(!rc_dig_in05, &pwm03);
This line passes the address of the pwm03 variable to the Limit_Switch_Max function for it to use as a pointer back to the memory location occupied by the pwm03 variable.

Does this help? If you can give us some clues about what you're trying to do with pointers (and how much you already know or don't know about pointers), I imagine we can be a little more helpful.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
  #5   Spotlight this post!  
Unread 11-05-2004, 12:51 PM
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Can't use pointers nor refrences.

Sort of offtopic, but do you know why IFI used a pointer in the Limit_Switch_Max() function? I can't see any good reason except possibly to show that it could be done?
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award
  #6   Spotlight this post!  
Unread 11-05-2004, 12:56 PM
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
Re: Can't use pointers nor refrences.

Quote:
Originally Posted by Max Lobovsky
Sort of offtopic, but do you know why IFI used a pointer in the Limit_Switch_Max() function? I can't see any good reason except possibly to show that it could be done?
They're passing the PWM value by reference so they can update it from inside the function.
  #7   Spotlight this post!  
Unread 11-05-2004, 12:58 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,548
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Can't use pointers nor refrences.

Quote:
Originally Posted by Max Lobovsky
Sort of offtopic, but do you know why IFI used a pointer in the Limit_Switch_Max() function? I can't see any good reason except possibly to show that it could be done?
If they hadn't, they would have to change Limit_Switch_Max to type unsigned char (instead of void) and return the value of either input_value or 127.

Or is that what you referring to?
  #8   Spotlight this post!  
Unread 11-05-2004, 02:13 PM
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: Can't use pointers nor refrences.

Sorry, I should have been a bit more clear. I know they were passing it by pointer so they could change it inside the function, but I would have thought it better practice to return the value than output from inside the function. Isn't it good practice, in general, to have functions be as close to real mathematical functions as possible (one set of inputs always maps to the same outputs and the only outputs are what the function returns)
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award

Last edited by Max Lobovsky : 11-05-2004 at 02:41 PM.
  #9   Spotlight this post!  
Unread 11-05-2004, 02:21 PM
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Can't use pointers nor refrences.

Quote:
Originally Posted by cibressus53
Has anyone had any sucess with using pointers or refrences? I thought MLAB was C '89 compleient, I thought pointers atleast were in the orignal C "release"
Just a warning that references aren't C. (Hence why they may not be working. C++ only. )
__________________

  #10   Spotlight this post!  
Unread 11-05-2004, 03:44 PM
Steve Shade Steve Shade is offline
Registered User
no team
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1999
Location: Pasadena, MD
Posts: 78
Steve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud ofSteve Shade has much to be proud of
Re: Can't use pointers nor refrences.

Quote:
Originally Posted by Max Lobovsky
..., but I would have thought it better practice to return the value than output from inside the function. Isn't it good practice, in general, to have functions be as close to real mathematical functions as possible (one set of inputs always maps to the same outputs and the only outputs are what the function returns)
Generally speaking, you are correct. If I or one of my team members were to write a function similar to the one Greg pointed out, we would have used a return statement and made the function of type unsigned char. However, Innovation FIRST tries to give a wide variety of examples in the default code to facilitate teams in developing their own code. This example will help some people see the syntax of a pointer in code, or help them understand one of the trickier programming topics. In most cases, you want to avoid pointers when possible.

Steve

Last edited by Steve Shade : 11-05-2004 at 03:45 PM. Reason: spelling
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointers to structs? Jeff McCune Programming 2 02-17-2004 01:17 PM
Laser Pointers.. archiver 2001 18 06-24-2002 12:08 AM


All times are GMT -5. The time now is 03:57 PM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi