From c76a8657b3324a7ce203665bbdc720a4f706bf48 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 3 Aug 2008 15:30:03 +0000 Subject: [PATCH] Fixed handling of function definitions with an empty parameter list. According to the standard, an empty parameter list in a function declarator that is not a definition means that the function may have any number of parameters. In a function definition, it means that there are no parameters (as if the function were declared with a "void" parameter list). git-svn-id: svn://svn.cc65.org/cc65/trunk@3865 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/compile.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 411c31357..24ef4aa70 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 2000-2004 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 2000-2008 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -250,12 +250,28 @@ static void Parse (void) if (CurTok.Tok == TOK_SEMI) { /* Prototype only */ NextToken (); - } else if (Entry) { - /* Function body definition */ + } else { + + FuncDesc* D; + + /* Function body. Check for duplicate function definitions */ if (SymIsDef (Entry)) { Error ("Body for function `%s' has already been defined", Entry->Name); } + + /* An empty parameter list in a function definition means + * that the function doesn't take any parameters. The same + * in a declarator means that the function can take any + * number of parameters. This seems weird but is necessary + * to support old K&R style programs. + */ + D = Entry->V.F.Func; + if (D->Flags & FD_EMPTY) { + D->Flags = (D->Flags & ~(FD_EMPTY | FD_VARIADIC)) | FD_VOID_PARAM; + } + + /* Parse the function body */ NewFunc (Entry); } } -- 2.39.5