]> git.sur5r.net Git - cc65/commitdiff
Fixed handling of function definitions with an empty parameter list. According
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 3 Aug 2008 15:30:03 +0000 (15:30 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 3 Aug 2008 15:30:03 +0000 (15:30 +0000)
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

index 411c31357f60b3a494e2ce053599aa3b70e97f6a..24ef4aa70135e686a3259e34a2d6720e94321fde 100644 (file)
@@ -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);
                }
            }