Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Aliases (http://www.chiefdelphi.com/forums/showthread.php?t=17634)

Steven Carmain 09-02-2003 06:14

Aliases
 
Can you make a temp variable, give it like 4 aliases and use anyone of them? This may be very effective if you use put and get statements because of our variable space.

Nate Smith 09-02-2003 09:09

I haven't seen anything that would keep you from doing this...

Greg Ross 09-02-2003 14:56

Re: Aliases
 
Quote:

Originally posted by Steven Carmain
Can you make a temp variable, give it like 4 aliases and use anyone of them? This may be very effective if you use put and get statements because of our variable space.
We've done exactly this the last few years.

Gobiner 10-02-2003 06:59

The way I understand it, you can use as many aliases as you want because all the variables are turned into memory addresses when tokenized.

rust710 10-02-2003 07:22

When a varable is aliased is the value the same for all aliased names?

Jeff Waegelin 10-02-2003 08:57

Quote:

Originally posted by rust710
When a varable is aliased is the value the same for all aliased names?
Yes. All aliases for a given variable have the same value. When the code is tokenized, all aliases point to the same spot in memory, so they are essentially the same variable.

Anthony Kesich 11-02-2003 00:42

sooo....
 
so then why alias a variablle to different names? if they all equal the same thing, why not just use the same one again and again, it would save code and space. Is it just for ease and readability?

-Kesich

rbayer 11-02-2003 01:07

Re: sooo....
 
Quote:

Originally posted by Anthony Kesich
so then why alias a variablle to different names? if they all equal the same thing, why not just use the same one again and again, it would save code and space. Is it just for ease and readability?

-Kesich

That's the main reason. The other reason is if you want to access smaller portions of a variable. For example, relay1_fwd is an alias of the relayA variable, but only points to one bit inside it.

Jnadke 11-02-2003 02:11

Re: sooo....
 
Quote:

Originally posted by Anthony Kesich
Is it just for ease and readability?

-Kesich


Bingo. When your robot breaks down next year and you urgently need it to do a demonstration to get some team funds, you'll want to know what the heck you were thinking when you wrote the code.


I always use the default names for the SERIN so I know what's being input, then I alias them for my code so that I know what I'm doing. It helps the train of thought because then you can read it more like a sentence.

Mike Soukup 11-02-2003 14:36

Re: sooo....
 
Quote:

Originally posted by Anthony Kesich
so then why alias a variablle to different names? if they all equal the same thing, why not just use the same one again and again, it would save code and space. Is it just for ease and readability?
You don't lose any program space when you alias variables. When the code is compiled (or tokenized if you prefer) all the names are converted to memory addresses. The processor has no idea that you've created aliases. All it gets is a command to fetch some data from a memory location.

Besides code readability, a reason to use aliases the way Jnadke said is to quickly change the input mapping. If you want to switch your drive stick to port 2 instead of port 1 and you don't have any aliases, you have to change all the occurrances of p1_x and p1_y to p2_x and p2_y respectively. If you use aliases such as drive_stick_x and drive_stick_y, all you have to do is change the alias in one place and you're done.

You should do the same for your outputs as well. Or you can write your motor output speeds to scratchpad RAM locations (such as s_left_drive_speed) and then fetch your speed to the correct pwm variable right before the Serout.

Those are just a few tricks to make changing input & output mappings less of a headache.

Anthony Kesich 11-02-2003 22:23

uhhuh
 
ahh i see...., so it makes it much easier. (you'll have to excuse me, im a rookie programmer, err the only programmer on a rookie team, and ive taught myself all of the code, so i have learned to question EVERYTHING)

-Kesich

P.S. I've had that problem many times before, changing ports that is, and i find it to be a pain in th neeck, expecially when you miss ONE of them and it destroys the entire operation.


All times are GMT -5. The time now is 04:28.

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