scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 321ff05de46a7eaf967e73364dd02fa70c08518a
parent 9c8462aa2508d754ae0d9e1dcddcd7883ec0b129
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 10 Feb 2012 08:49:57 +0100

Added declaration of default integers

When a variable is defined without type, its default type is
integer. In C99 this rule is removed , but is common in compilers
continuing using it.

Conflicts:

	types.c

Diffstat:
decl.c | 72++++++++++++++++--------------------------------------------------------
1 file changed, 16 insertions(+), 56 deletions(-)

diff --git a/decl.c b/decl.c @@ -93,8 +93,10 @@ struct type *types[][2] = {{T_VOID, NULL}, struct type *specifier(void) { static char sign, sclass, tqlf, nt; - struct type *t = NULL; + struct type *t; +repeat: + t = NULL; tqlf = sign = sclass = 0; for (;;) { switch (gettok()) { @@ -126,8 +128,20 @@ struct type *specifier(void) case STRUCT: /* TODO */ case UNION: /* TODO */ case ENUM: /* TODO */ + case ';': + if (t != NULL) { + warning("useless type name in empty " + "declaration"); + } + goto repeat; case IDENTIFIER: - /* TODO */ + /* TODO: deal with user types */ + if (t == NULL) { + warning_error(user_opt.implicit_int, + "type defaults to 'int' " + "in declaration of", yytext); + return T_INT; + } default: return t; } @@ -236,60 +250,6 @@ void declaration(void) } -#if 0 -void specdcl(void) -{ - struct spec_type t = {0, 0, 0}; - -repeat: - parser_out_home = 1; - switch (gettok()) { - case TYPEDEF: - case EXTERN: - case STATIC: - case AUTO: - case REGISTER: - case CONST: - case VOLATILE: - case SIGNED: - case UNSIGNED: - if (!(t.mods ^= MODIFIER(tok))) - error("duplicate '%s'", yytext); - goto repeat; - case IDENTIFIER: - /* This is incorrect!!! */ - t.type = TYPE(INT); - if (user_opt.implicit_int) { - warning_error(user_opt.c99, - "type defaults to ‘int’ in declaration" - " of", yytext); - } - if (gettok() != ';') - goto non_end_after_id; - return ';'; - case VOID: - case CHAR: - case INT: - case LONG: - case FLOAT: - case DOUBLE: - if (!(t.type ^= (1 << TYPE(tok)))) - error("duplicate '%s'", yytext); - - case STRUCT: - case UNION: - case ENUM: - case TYPE_NAME: - ; - } - - -non_end_after_id: - error("';' expected"); -} -#endif - - #include <stddef.h>