enum error

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Trying to use an enum

typedef enum {FALSE, TRUE} bool_t;

but get the following:

error:syntax error before numeric constant

It doesn't seem to like the keyword enum?!?

Using WinAVR-20060421

Tried commenting-out the following:

CFLAGS += -fshort-enums

as per an old posting but didn't help

Thanks for any leads to sorting this out.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have an error somewhere else (maybe a missed semi-colon?) because there's nothing wrong with the line you gave - I just copied it and compiled it without error.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff,

But everything compiled (and worked) OK before I put this one line in!

It was suggested at a code review to use an enum rather than #defines, but can'na get it to work.

I am using the makefile in WinAVR/sample that came with WinAVR-20060421

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Then it's the context of where this line has been placed in amongst others that is the problem. Can you post a few lines above/below the problem?

"can'na" - Scottish by any chance? ;)

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is in the source file that includes main() in it.

#include 
#include 
#include "global.h"
#include "a2d.h"
#include "i2cmaster.h"
#include "serial.h"
#include "uart.h"


#define RTC_CORRECTION 0x04   // 4 seconds
#define BUCKETS 32   
#define Dev24C64 0xA2         // 1010 0010 A0 pulled high, A1 and A2 grounded
#define RTC_ADDR 0xD0         // 1101 0000 DS-1307 RTC
#define RTC_1Hz_INTERRUPT_HANDLER SIGNAL 

#define FOREVER for(;;)
#define NUMBER_OF_DATA_BYTES 1
#define _NOP() do { __asm__ __volatile__ ("nop"); } while (0)
// approxiamtely an 8us delay with a 3.6864MHz xtal
#define DOWNLOAD_EEPROM 0x01
#define NOT_USED 0x02 
#define SET_RTC 0x03
#define READ_RTC 0x04


volatile u08 RTC_1Hz_interrupt_flag;
typedef enum {FALSE, TRUE} bool_t; // gives error
typedef struct {
      u08 reset_pointer;
      u08 seconds;       
      u08 minutes;
      u08 hours;
      u08 day_of_the_week;
      u08 date;
      u08 month;
      u08 year;
      u08 control_register;
   }RTC_data_s;            

  
void initialise_hardware(void);
void initialise_EEPROM_1(void);
u08 setRTC(void);
void read_RTC(RTC_data_s *RTC_data_ptr);
RTC_1Hz_INTERRUPT_HANDLER(INT2_vect);
u08 bcd_to_hex(u08 bcd);
u08 hex_to_bcd(u08 hex_number);


int main(void)
 {:} 

Can'na just used for emphasis!

Thanks,
Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well I had to modifiy it a bit because I haven't got some of the .h files listed but:

#include  
#include  
#if 0 
#include "global.h" 
#include "a2d.h" 
#include "i2cmaster.h" 
#include "serial.h" 
#include "uart.h" 
#endif

typedef unsigned char u08;

#define RTC_CORRECTION 0x04   // 4 seconds 
#define BUCKETS 32    
#define Dev24C64 0xA2         // 1010 0010 A0 pulled high, A1 and A2 grounded 
#define RTC_ADDR 0xD0         // 1101 0000 DS-1307 RTC 
#define RTC_1Hz_INTERRUPT_HANDLER SIGNAL 

#define FOREVER for(;;) 
#define NUMBER_OF_DATA_BYTES 1 
#define _NOP() do { __asm__ __volatile__ ("nop"); } while (0) 
// approxiamtely an 8us delay with a 3.6864MHz xtal 
#define DOWNLOAD_EEPROM 0x01 
#define NOT_USED 0x02 
#define SET_RTC 0x03 
#define READ_RTC 0x04 


volatile u08 RTC_1Hz_interrupt_flag; 
typedef enum {FALSE, TRUE} bool_t; // gives error 
typedef struct { 
      u08 reset_pointer; 
      u08 seconds;        
      u08 minutes; 
      u08 hours; 
      u08 day_of_the_week; 
      u08 date; 
      u08 month; 
      u08 year; 
      u08 control_register; 
   }RTC_data_s;            

  
void initialise_hardware(void); 
void initialise_EEPROM_1(void); 
u08 setRTC(void); 
void read_RTC(RTC_data_s *RTC_data_ptr); 
RTC_1Hz_INTERRUPT_HANDLER(INT2_vect); 
u08 bcd_to_hex(u08 bcd); 
u08 hex_to_bcd(u08 hex_number); 


int main(void) 
 {;} 

compiles without warning/error for me ?!?

Implies that there's something in one of those header files muddying the water - could TRUE/FALSE already be defined in one of them perhaps?

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah, global.h includes avrlibtypes.h which has the following:

#ifndef AVRLIBTYPES_H
#define AVRLIBTYPES_H

#ifndef WIN32
// true/false defines
#define FALSE 0
#define TRUE -1
#endif

I thought the above meant that FALSE and TRUE were not being included.

I changed FALSE and TRUE to RED and GREEN , in the original source and it compiles properly.

Looks like I need read up on #ifndef a bit more carefully!

Thanks for the helping out and providing the solution.
Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

#ifndef is "if NOT defined". That code will define TRUE and FALSE as -1 and 0 respectivly, but only if "WIN32" is not already defined. Since your AVR app isn't a WIN32 application, and thus the Windows APIs havn't already defines TRUE and FALSE, that defines them for you and you get your error.

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Dean.

Think I have achieved (almost) total clarity now!

Why would this be included in a library for the AVR?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now that I CAN'T answer - it boggles my mind and causes an internal exception error. Why anyone thought that an AVR library needed WIN32 library protection is beyond me. A "better" implementation would be to test for previous definitions of the macros themselves:

#if !defined(TRUE) && !defined(FALSE)
#define FALSE 0
#define TRUE !(FALSE)
#end if

- Dean :twisted:

Make Atmel Studio better with my free extensions. Open source and feedback welcome!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#ifndef TRUE
#define TRUE  1
#endif

#ifndef FALSE
#define FALSE 0
#endif

typedef enum { false = FALSE, true } bool;
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#ifndef __cplusplus
#ifndef TRUE
#define TRUE  1
#endif

#ifndef FALSE
#define FALSE 0
#endif

typedef enum { false = FALSE, true = TRUE} bool;
#endif

bool is a standard type in C++.

Markus

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks everyone for the help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

davef wrote:
Why would this be included in a library for the AVR?

Possibly for test purposes?
Maybe the author had some sort of windoze-based test harness?

Or maybe it's just a general-purpose bit of code, which just happens not to be relevant in this particular case?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...