真的很简单;我可能忘记了一个分号

时间:2010-09-07 21:05:12

标签: c gcc

我遇到了很多这样的错误:

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
...

我有点累,所以我无法弄清楚是什么原因造成的。

这是buffer的定义(从第43行开始,转到第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

(它旨在支持多架构8位MCU到32位MCU。)

我已经定义了uint8_t等因为我正在使用的GCC似乎没有stdint.h头。

以下是我如何定义uint8_t等。

/* 
 * 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

2 个答案:

答案 0 :(得分:1)

warning: no semicolon at end of struct or union表示您在之前在同一文件中定义的structunion或之前包含的其他标头中已经分隔了分号。这将导致格式错误的陈述,例如:

struct S { ... } uint8_t buffer[GFX_SIZE];

答案 1 :(得分:0)

我显然已经解决了我的问题。

我的错误是在uint8_t和朋友的“typedef”定义之前没有声明PROC_BIT_SIZE。因此预处理器忽略了声明,导致错误。

只是我自己制造的错误。