From: Eric Backus Subject: Re: Pre-processor bug (?) To: djgpp AT sun DOT soe DOT clarkson DOT edu (djgpp) Date: Tue, 21 Apr 92 17:51:22 PDT Mailer: Elm [revision: 66.25] Status: O Laurent Duperval writes: > I get the following errors: > > cmd.c: In function `lowc': > cmd.c:819: argument `sym' doesn't match function prototype > cmd.c:819: a formal parameter type that promotes to `int' > cmd.c:819: can match only `int' in the prototype ... more of the same ... > > The only way I have found, so far, to correct the problem is to rewrite > the definitions and the headers as standard C, i.e: > > int movecmd(char); > int movecmd(char c) > { > function body > } > > The same code compiles under BC++ 2.0 but not under DJGPP 1.06. Exactly > what is wrong? What is wrong is pretty much what the compiler says is wrong. In traditional non-ANSI C, a function that declared a parameter as "char" or "short" really expected to get an "int" passed to it, and the function did the necessary conversion of the int to whatever it wanted. The caller of the function knew to promote a "char" or "short" parameter to "int" before pushing it on the stack, so everything worked out. In ANSI C, a function can use a new-style function declaration to specify that it really wants the unpromoted "char" or "short" parameter. And a new-style function prototype can tell the caller of the function that the function doesn't want a "char" or "short" parameter promoted to "int". The problem comes when there is a new-style function prototype (which tells the caller to push a char or short), but the function itself is declared in the old-style that doesn't have the parameter types inside the parentheses. The caller then pushes a "char" or "short", but the function itself is expecting to receive an "int" on the stack. The compiler could deal with this, but this is not correct code according to ANSI C, and this is why the compiler is giving you the error. Apparently BC++ 2.0 works around this coding error without telling you about it. Moral: don't mix old-style function declaration with new-style function prototypes. -- Eric Backus ericb%hplsla AT hplabs DOT hp DOT com (206) 335-2495