diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 734256b97..49e233a56 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -684,21 +684,31 @@ static int ParseFieldWidth (Declaration* Decl) /* Read the width */ NextToken (); ConstAbsIntExpr (hie1, &Expr); + if (!IsClassInt (Decl->Type)) { + /* Only integer types may be used for bit-fields */ + Error ("Bit-field has invalid type ''"); + return -1; + } if (Expr.IVal < 0) { Error ("Negative width in bit-field"); return -1; } - if (Expr.IVal > (int) INT_BITS) { + /* FIXME: We should compare with the width of the specified type */ +#if 0 + /* Use is when we really support non-uint16_t bit-fields */ + if (Expr.IVal > (long)(SizeOf (Decl->Type) * CHAR_BITS)) { Error ("Width of bit-field exceeds its type"); return -1; } - if (Expr.IVal == 0 && Decl->Ident[0] != '\0') { - Error ("Zero width for named bit-field"); +#else + /* This is what we currenty do */ + if (Expr.IVal > (long)(SizeOf (type_uint) * CHAR_BITS)) { + Error ("Width of bit-field exceeds 16"); return -1; } - if (!IsTypeInt (Decl->Type)) { - /* Only integer types may be used for bit-fields */ - Error ("Bit-field has invalid type"); +#endif + if (Expr.IVal == 0 && Decl->Ident[0] != '\0') { + Error ("Zero width for named bit-field"); return -1; }