tags:

views:

86

answers:

2

I'm getting loads of errors like these:

gfx.h:48: error: syntax error before 'buffer'

gfx.h:48: warning: type defaults to 'int' in declaration of 'buffer'

gfx.h:48: warning: data definition has no type or storage class

gfx.h:73: error: syntax error before 'uint16_t'

gfx.h:73: warning: no semicolon at end of struct or union

gfx.h:74: warning: type defaults to 'int' in declaration of 'visible_lines_per_frame'

gfx.h:74: warning: data definition has no type or storage class
...

I'm a bit tired, so I can't figure out what could be causing these.

This is the definition of buffer (starting at line 43, going to line 57):

/* 8-bit architecture (not yet used.) */
#if   PROC_BIT_SIZE == 8
uint8_t buffer[GFX_SIZE];
# define GFX_PIXEL_ADDR(x,y) (x / 8) + (y * (GFX_WIDTH / 8))
/* 16-bit architecture: dsPIC */
#elif  PROC_BIT_SIZE == 16
uint16_t buffer[GFX_SIZE / 2];
# define GFX_PIXEL_ADDR(x,y) (x / 16) + (y * (GFX_WIDTH / 16))
/* 32-bit architecture: AVR32(?), STM32 */
#elif  PROC_BIT_SIZE == 32
uint32_t buffer[GFX_SIZE / 4];
# define GFX_PIXEL_ADDR(x,y) (x / 32) + (y * (GFX_WIDTH / 32))
/* Other, unknown bit size.*/
#else
# error "processor bit size not supported"
#endif

(It's designed to support multiple architectures 8-bit MCUs to 32-bit MCUs.)

I've defined uint8_t etc. because the GCC I'm using doesn't seem to have a stdint.h header.

Here is how I have defined uint8_t etc.

/* 
 * stdint.h support.
 * If your compiler has stdint.h, uncomment HAS_STDINT.
 */
//#define HAS_STDINT
#ifndef HAS_STDINT
// D'oh, compiler doesn't support STDINT, so create our own,
// 'standard' integers.
# if PROC_BIT_SIZE == 8 || PROC_BIT_SIZE == 16
typedef char int8_t;
typedef int int16_t;
typedef long int32_t;
typedef long long int64_t;
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long uint32_t;
typedef unsigned long long uint64_t;
# elif PROC_BIT_SIZE == 32
typedef char int8_t;
typedef short int16_t;
typedef int int32_t; // usually int is 32 bits on 32 bit processors, but this may need checking
typedef long int64_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long uint64_t;
# endif
#else
# include <stdint.h>
#endif
+1  A: 

The warning: no semicolon at end of struct or union implies that you've left a semicolon off at the end of a struct or union defined earlier in the same file, or in another header that was included earlier. This would result in malformed statements such as:

struct S { ... } uint8_t buffer[GFX_SIZE];
Jon Purdy
A: 

I apparently have solved my problem.

My mistake was to not declare PROC_BIT_SIZE before the "typedef" definitions of uint8_t and friends. The preprocessor therefore ignored the declarations, causing the error.

Just a blunder of my own making.

Thomas O
One way to avoid that in the future is to add an `#else` section to the `#if PROC_BIT_SIZE == ` block that says `#error PROC_BIT_SIZE not defined`.
bta
Is #error standard C preprocessor?
mathepic
@mathepic: Yes.
caf