PDA

View Full Version : Syntax Error: externs, structs, and macros


Astronouth7303
02-14-2005, 09:49 PM
Here's the thing: I'm getting a syntax error in 2 seperate lines that are probably related. I have narrowed it down to the point that I know that it is not the next or previous line.

They are:

BEGIN_MOTOR_LIST(motor_list)
MOTOR(STRAIGHT, LeftDrive, OI_Left, 0, 0, 0, 0, 0, 254, 254) //ME! ME!
//...
END_MOTOR_LIST


REF_MOTOR_LIST(motor_list);


Here are the dependencies needed to get this:

#ifdef _MOTORS_H_
#define _MOTORS_H_

typedef enum {NONE,STRAIGHT,POSITION,FISHER} MotorType;

struct motors
{
enum Motor type;
char* pwm;
char* oi;
char pot;
char pot_min;
char pot_max;
char pot_center;
char pwm_min;
char pwm_max;
char pwm_change;
}

#define BEGIN_MOTOR_LIST(name) struct motors rom name[] = {
#define END_MOTOR_LIST {NONE, 0, 0, 0, 0, 0, 0, 0, 0} };
#define REF_MOTOR_LIST(name) extern struct motors name[]
#define PTR_MOTOR_LIST(name) struct motors *name
#define MOTOR(type,pwm,oi,pot,pot_min,pot_max,pot_center,p wm_min,pwm_max,pwm_change) {type, &pwm, &oi, pot, pot_min, pot_max, pot_center, pwm_min, pwm_max, pwm_change },

void DoMotors(PTR_MOTOR_LIST(motorlist));
#endif


char LeftDrive, RightDrive, E2;
#define OI_Left p1_y

(unfortunately, it inserted random spaces)

Enlightenment?

Orborde
02-14-2005, 10:54 PM
#define MOTOR(type,pwm,oi,pot,pot_min,pot_max,pot_center,p wm_min,pwm_max,pwm_change) {type, &pwm, &oi, pot, pot_min, pot_max, pot_center, pwm_min, pwm_max, pwm_change },
Might it be the marked bit?

Dave Flowerday
02-15-2005, 12:30 AM
I didn't spot anything wrong off-hand (other than the space noted by the previous poster, but I'm guessing that was a copy/paste problem?). Something you might try to narrow down the problem is pre-processing the C file to see how your macros worked out. There should be a cpp18.exe as part of the MCC18 package - this is the C preprocessor. Just run:
cpp18 {filename}.c -I{path to MCC18 include directory} > {filename}.pre
and it will spit the preprocessed file out to {filename}.pre. That might yield some clues.

Astronouth7303
02-16-2005, 03:39 PM
#define MOTOR(type,pwm,oi,pot,pot_min,pot_max,pot_center,p wm_min,pwm_max,pwm_change) {type, &pwm, &oi, pot, pot_min, pot_max, pot_center, pwm_min, pwm_max, pwm_change },
Might it be the marked bit?
Nope. That's just from the post. Try as I did, I couldn't get rid of it. But it doesn't exist in the file.

I didn't spot anything wrong off-hand (other than the space noted by the previous poster, but I'm guessing that was a copy/paste problem?). Something you might try to narrow down the problem is pre-processing the C file to see how your macros worked out. There should be a cpp18.exe as part of the MCC18 package - this is the C preprocessor. Just run:
cpp18 {filename}.c -I{path to MCC18 include directory} > {filename}.pre
and it will spit the preprocessed file out to {filename}.pre. That might yield some clues.

Cool! Thanks! I'll try that! :cool: