|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
syntax error using enum{}
When I compile my code, the compiler says "syntax error" for one of my header files and points to the line shown below:
Code:
enum
{
START, <== this line causes syntax error
IN_PROGRESS,
DRIVING,
TURNING,
COMPLETE
};
Code:
enum
{
FOOSTART,
IN_PROGRESS, <=== now the error is here
DRIVING,
TURNING,
COMPLETE
};
I did a Build All (CTRL-F10) to make sure there wasn't a leftover symbol table. No difference. As a matter of practicality I renamed all the variables to start with an _underscore, and now it builds just fine. But it bugs me that I can't explain this error. Any ideas????? Here's the entire header file: Code:
#ifndef SCRIPTING_H
#define SCRIPTING_H
#define MAX_SCRIPTS 32 // more than this is an error from parseScript()
struct scriptCommand
{
int command;
long int parm_1;
int parm_2;
int parm_3;
};
// List of commands
//
enum
{
S_NAME, // marks the start of a script
S_END, // marks the end of a script
S_DRIVE, // <distance>, <maxSpeed>, <maxAccel>
S_TURN, // <heading>, <maxSpeed>, <maxAccel>
S_STOP,
S_WAIT, // <counts>
S_SET_ARM_POSITION, // <angle>, <speed>, <tolerance>
S_LIST_END
};
// List of all possible command states
// Not all are used in every command.
enum
{
START,
IN_PROGRESS,
DRIVING,
TURNING,
COMPLETE
};
int parseScript();
int startScript( int scriptCode );
int executingScript( ); // returns 1 if a script is executing.
void backAndForth();
void driveFromStartToLoading();
void knockOffHangingTetra();
void setArmPosition();
unsigned char sDrive();
unsigned char sTurn();
#endif
|
|
#2
|
|||||
|
|||||
|
Re: syntax error using enum{}
For one, enums aren't part of the C standard (unless they were add in ISO C99). Second, you have to give the enum a name. I believe the syntax is:
enum <name> { <enum values> }; Hope this is helpful. Matt |
|
#3
|
|||||
|
|||||
|
Re: syntax error using enum{}
Quote:
Besides, if enum{} wasn't allowed, just changing the names of the identifiers would not have eliminated the syntax error. But it did. I'm still confused. |
|
#4
|
|||||
|
|||||
|
Re: syntax error using enum{}
Quote:
Code:
/* Command States */ /* These states are used by the commands to keep track of the robot's progress in completing each command. */ #define START 1 #define IN_PROGRESS 2 #define COMPLETE 3 #define TURNING 4 #define DRIVING 5 #define STOPPED 6 Quote:
Last edited by Greg Ross : 04-02-2005 at 15:32. |
|
#5
|
|||||
|
|||||
|
Re: syntax error using enum{}
I think that's it. I had re-written robot.[h,c] but I think I have a residual #include "robot.h" in user_routines.c. I'll have to double check tonight, but I'm pretty sure that's it.
You'd think the compiler could have said something a little more helpful than "syntax error"... Thanks! -Norm |
|
#6
|
||||
|
||||
|
I can only agree with you about the error statement. I wasted hours trying to decipher these, while the problem was mainly as simple as giving a name to a parameter similiar to an existing macro, or ; being where it's not needed and vice versa
![]() |
|
#7
|
|||||
|
|||||
|
Re: syntax error using enum{}
That was indeed the error.
Yeah, the compiler is low on helpfulness. I accidentally created a local variable that shadowed a global variable but it gave no warning. Is there a way to increase the number of warnings for the compiler? Like gcc -Wall? |
|
#8
|
|||||
|
|||||
|
Re: syntax error using enum{}
Quote:
Then on the MPLAB C18 tab, set the Diagnostic Level="Errors, Warnings, and Messages" I make no guarantee, however, that it will catch these problems. |
|
#9
|
||||
|
||||
|
Re: syntax error using enum{}
Quote:
Code:
enum
{
1,
2,
3,
4,
5
};
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Routine declaration syntax error (Or: Where's wlado?) | Astronouth7303 | Programming | 15 | 24-03-2004 05:51 |
| BS2 syntax (PBASIC) on the new controllers? Maybe! | Jeremy_Mc | Programming | 0 | 25-10-2003 15:00 |
| PBASIC Syntax Question | Raven_Writer | Programming | 4 | 20-08-2003 08:07 |
| PBASIC language syntax | WizardOfAz | Programming | 14 | 30-04-2003 10:23 |
| UltraEdit Syntax Highlighting | Jeff McCune | Programming | 9 | 19-01-2003 20:08 |