Thread: Aliases
View Single Post
  #10   Spotlight this post!  
Unread 11-02-2003, 14:36
Mike Soukup's Avatar
Mike Soukup Mike Soukup is offline
Software guy
FRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1996
Location: Schaumburg, IL
Posts: 797
Mike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond reputeMike Soukup has a reputation beyond repute
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.