Go to Post Pompous boasts dont get you anywhere. Results get your name on the book... - Jeremy_Mc [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 04-02-2005, 13:48
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
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
};
When I rename the variable START to something else like FOOSTART, the error moves down to the next line:

Code:
enum
{
  FOOSTART,
  IN_PROGRESS,  <===  now the error is here
  DRIVING,
  TURNING,
  COMPLETE
};
I figured there must be a name conflict (since I'm using bits of Kevin's code), so I Searched in Project Files... for "IN_PROGRESS", but it is only defined in this one place. No conflict. As I modify each variable in the list, the error moves down the list.

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
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #2   Spotlight this post!  
Unread 04-02-2005, 13:56
Unsung FIRST Hero
Matt Leese Matt Leese is offline
Been-In-FIRST-Too-Long
FRC #1438 (The Aztechs)
Team Role: Engineer
 
Join Date: May 2001
Rookie Year: 1998
Location: Long Beach, CA
Posts: 937
Matt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond reputeMatt Leese has a reputation beyond repute
Send a message via AIM to Matt Leese
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   Spotlight this post!  
Unread 04-02-2005, 14:18
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
Re: syntax error using enum{}

Quote:
Originally Posted by Matt Leese
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>
};
According to my copy of K & R Second Edition (ANSI C Edition) enumerations are defined in Appendix A (Reference Manual) section A8.4. The identifier (what you show as <name>) is indicated as optional.

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.
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #4   Spotlight this post!  
Unread 04-02-2005, 15:25
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: syntax error using enum{}

Quote:
Originally Posted by gnormhurst
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.
All of those identifiers are #defined in robot.h:
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
I think this explains the mystery.
Quote:
I figured there must be a name conflict (since I'm using bits of Kevin's code), so I Searched in Project Files... for "IN_PROGRESS", but it is only defined in this one place. No conflict. As I modify each variable in the list, the error moves down the list.
"Find in Project Files" only searches files it knows about in the project. (i.e. listed in the project window), whereas, the compiler couldn't care less about the files in the IDE's list. It cares about #include statements only.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 04-02-2005 at 15:32.
  #5   Spotlight this post!  
Unread 04-02-2005, 16:02
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
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
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #6   Spotlight this post!  
Unread 04-02-2005, 16:38
Anton's Avatar
Anton Anton is offline
Anton Povzner
#1581 (Element)
Team Role: Programmer
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Israel
Posts: 51
Anton can only hope to improve
Smile Re: syntax error using enum{}

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   Spotlight this post!  
Unread 07-02-2005, 09:40
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
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?
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.
  #8   Spotlight this post!  
Unread 07-02-2005, 11:07
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Re: syntax error using enum{}

Quote:
Originally Posted by gnormhurst
You'd think the compiler could have said something a little more helpful than "syntax error"...
Agreed, but keep in mind what was happening: your "enum" values were being replaced with the #defines from robot.h, so to the compiler your enum ended up looking like this:
Code:
enum
{
  1,
  2,
  3,
  4,
  5
};
While that doesn't excuse the cryptic error generated, it might at least make sense why the compiler reported a syntax error (because it is!).
  #9   Spotlight this post!  
Unread 07-02-2005, 14:25
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: syntax error using enum{}

Quote:
Originally Posted by gnormhurst
Is there a way to increase the number of warnings for the compiler? Like gcc -Wall?
You can set the message level: Project | Build Options | Project

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.
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 19:20.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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