View Single Post
  #1   Spotlight this post!  
Unread 20-02-2005, 00:55
Vincent Chan's Avatar
Vincent Chan Vincent Chan is offline
the Friendly Team Asian
#1127 (Lotus Robotics)
Team Role: Student
 
Join Date: Feb 2003
Location: Alpharetta, GA
Posts: 125
Vincent Chan is on a distinguished road
Send a message via AIM to Vincent Chan
C: Cascading for Aliases?

I'm the interim programmer for our team, and I'm trying to write some dead-reckoning code for the robot. I've currently got all my dead-reckoning strategies written in a .h file as an array of command type structures, much like the demo gyro code, but I need to be able to switch between them.

We're using a DIP switch to choose the strategy we want, and I was wondering if I could use an array variable of command type structures in my functions that is aliased via a cascading-if in my code. (It would look something like this

Code:
command struct command_list[];
if(dipswitch == 0)
      command_list[] = strat1_list[]; //strat1_list[] is defined in an included h file
else if(dipswitch == 1)
      command_list[] = strat2_list[];
and so on and so forth, with a method calling it like this:

Code:
int move_forward(void)
{
     end_time = command_list[current_command].parm_1;
     if(curr_time > end_time)
            rc = 1;
     else
            rc = 0;
}
(So that you can understand what's going on, end_time would be the time at which you stop moving forward, and curr_time would count millisecs since the match began. You would grab the parameter that end_time is set to from a command type structure out of an array of those structs. command_list[] is that array and current_command is a variable that increments as commands are completed.)

Our mentor wasn't sure whether the aliasing of arrays was legal in C, though it seems like it should be, and I need to change a pretty sizeable chunk of code to find out. Anyone have any ideas?
__________________
Lotus Robotics, Team #1127

"So everybody's got ideas. Ideas are cheap. What's unique is the conviction to follow through: to work at it until it pays off. That's what separates the person who thinks I wonder why they can't just make shampoo and conditioner in one? from the one who thinks Now, should I get the Mercedes, or another BMW?"
--Scat, in Syrup by Maxx Barry