Go to Post Just keep doing. Everything. Keep designing, keep building, keep learning, keep fundraising. Build more robots, try more ideas, compete more and more and more. - [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 16-01-2004, 13:36
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Probably a basic question, but....

Ok, I've never known what this code actually does:

PHP Code:
/**  example only **/
   
int hi 0;
   
   return 
hi 0 0
Could someone explain that to me please?

My books don't have any explination (sp?) on that.
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"

Last edited by Raven_Writer : 16-01-2004 at 13:54.
  #2   Spotlight this post!  
Unread 16-01-2004, 13:56
Jay Lundy Jay Lundy is offline
Programmer/Driver 2001-2004
FRC #0254 (The Cheesy Poofs)
Team Role: Alumni
 
Join Date: Jun 2001
Rookie Year: 2001
Location: Berkeley, CA
Posts: 320
Jay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to allJay Lundy is a name known to all
Re: Probably a basic question, but....

Quote:
Originally Posted by Raven_Writer
Ok, I've never known what this code actually does:

PHP Code:
/**  example only **/
   
int hi 0;
   
   return 
hi 0 0
Could someone explain that to me please?

My books don't have any explination (sp?) on that.
The ? : is called the ternary operator. It's a more compact way of doing if statements. The format is:

conditional statement ? statement executed if true : statement executed if false;

I'm assuming that extra 0 stuck in there after hi is a typo?
  #3   Spotlight this post!  
Unread 16-01-2004, 13:56
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Probably a basic question, but....

are you sure it's not

Code:
int hi = 0;

return hi ? 1 : 0;
what i've just written is equivalent to this:

Code:
int hi = 0;

if(hi) return 1;
else return 0;
basically, the code
Code:
a ? b : c;
means "replace this with b is a is true, otherwise, replace this with c"

so you could use
Code:
var1 += (x>2 ? 4 : 1);
to increment var1 by 4 if x is greater than 2, but only by 1 if x is less than or equal to 2.

it's more than just a compact way of doing if statements, as i've illustrated - you can't embed a if statement in an expression, whereas you can embed the ternary operator.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #4   Spotlight this post!  
Unread 16-01-2004, 14:01
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: Probably a basic question, but....

Quote:
Originally Posted by Jay Lundy
The ? : is called the ternary operator. It's a more compact way of doing if statements. The format is:

conditional statement ? statement executed if true : statement executed if false;

I'm assuming that extra 0 stuck in there after hi is a typo?
Yea, I was typing kinda/pretty fast then.

Quote:
Originally Posted by deltacoder1020
are you sure it's not
Code:
  	int hi = 0;
 
 return hi ? 1 : 0;
what i've just written is equivalent to this:
Code:
  	int hi = 0;
 
 if(hi) return 1;
 
 else return 0;
basically, the code
Code:
 	a ? b : c;
means "replace this with b is a is true, otherwise, replace this with c"
Thanks, that really clears it up (also thanks to you Jay ).

It might make if-case statements more easier
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #5   Spotlight this post!  
Unread 16-01-2004, 18:59
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: Probably a basic question, but....

Here's another question....

I was searching through the default code for the tracking. I opened up "ifi_default.h", and saw that in the struct's, it'd have like: "unsigned int pie:1;"

My question now is, does the colon take the place of the equal sign?
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #6   Spotlight this post!  
Unread 16-01-2004, 20:07
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: Probably a basic question, but....

Quote:
Originally Posted by Raven_Writer
Here's another question....

I was searching through the default code for the tracking. I opened up "ifi_default.h", and saw that in the struct's, it'd have like: "unsigned int pie:1;"

My question now is, does the colon take the place of the equal sign?
The :1 indicates pie occupies a single bit.
__________________
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
  #7   Spotlight this post!  
Unread 16-01-2004, 20:51
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Re: Probably a basic question, but....

Quote:
Originally Posted by gwross
The :1 indicates pie occupies a single bit.
Thank you for clearing that up for me.

I just that it was another way to assign a variable.
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #8   Spotlight this post!  
Unread 17-01-2004, 01:04
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
Re: Probably a basic question, but....

it basically allows you to save space - you could use each of the 16 bits of an int to store a different 1/0 value, approximating a set of 16 booleans
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
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
A question about control system options computhief263 Control System 7 04-02-2004 14:46
Very Basic Programming Question kewlkid382 Chit-Chat 5 18-01-2003 11:11
Rookie Programmer has question about the default code DanL Programming 3 26-01-2002 19:59
Question about Basic Stamp miketwalker Programming 3 14-01-2002 13:10
Have a question about the Basic Stamp Chip Boards wes16zeus Programming 3 06-12-2001 08:25


All times are GMT -5. The time now is 20:00.

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