[gnu.gcc] Prototyping promotion problem.

sean@ms.uky.edu (Sean Casey) (02/27/90)

Could someone explain what the heck I am supposed to do about the
following? It seems to me that if your prototype matches the
declaration, everything should be hunky dory.

1. Is this problem typical to all ANSI C compilers?
2. The variable *must* be char. What am I supposed to do?

(prototypes.h)
int addusage(char *name, char type, char *args, char *usage);

(function def, this file includes prototypes.h)
addusage(name, type, args, usage)
char *name;
char type;
char *args;
char *usage;
{
	etc.
}

(error message)
	gcc -g -pg  -DSTRINGS_H -DTIME_H -c usage.c &151
usage.c: In function addusage:
usage.c:38: argument `type' doesn't match function prototype
usage.c:38: a formal parameter type that promotes to `int'
usage.c:38: can match only `int' in the prototype

151: *** Error code 1
Make: .  Stop.
-- 
***  Sean Casey          sean@ms.uky.edu, sean@ukma.bitnet, ukma!sean

sean@ms.uky.edu (Sean Casey) (02/27/90)

I write:

|Could someone explain what the heck I am supposed to do about the
|following? It seems to me that if your prototype matches the
|declaration, everything should be hunky dory.

One thing you need to know is that prototypes.h is automatically
generated. In all the source files, ff _STDC_ or _GNUC_ is defined,
prototypes.h is included. Otherwise, functypes.h (which consists of
prototypes.h with everything inside the parentheses deleted) is included. That
way, my code works on pcc and uses prototypes on GCC.

I still don't see why the compiler needs to cough on it when the two
match up exactly. It's very frustrating. I just want to make sure the
types match. Maybe I can turn off the promotion? Maybe I can tell GCC
"I don't care what promotes to what."

From the advice I've gotten so far, I guess I'm going to have to edit
prototypes.h by hand (or by perl) and change all "flat" character
references to int, or put in ifdefs for every procedure header. Yech.

Sean
-- 
***  Sean Casey          sean@ms.uky.edu, sean@ukma.bitnet, ukma!sean

wood%lavc3.dnet@SMITHKLINE.COM (Bill Wood, SmithKline&French R&D, 215-270-5163) (02/27/90)

In your function def, use the ANSI C format of declaring the arg type
in the argument list:

addusage(char *name, char type, char *args, char *usage)
{
...
}

I think this will work, although what you did seems like it should work since
you included prototypes.h in the file which contained the function def, and
the latest prototype should have applied...

- Bill              wood@smithkline.com

kjones@talos.pm.com (Kyle Jones) (02/28/90)

Sean Casey writes:
 > (prototypes.h)
 > int addusage(char *name, char type, char *args, char *usage);
 > 
 > (function def, this file includes prototypes.h)
 > addusage(name, type, args, usage)
 > char *name;
 > char type;
 > char *args;
 > char *usage;
 > {
 > 	etc.
 > }
 > 
 > (error message)
 > 	gcc -g -pg  -DSTRINGS_H -DTIME_H -c usage.c &151
 > usage.c: In function addusage:
 > usage.c:38: argument `type' doesn't match function prototype
 > usage.c:38: a formal parameter type that promotes to `int'
 > usage.c:38: can match only `int' in the prototype

You're using an old-style function definition, which ANSI C compilers
interpret to mean "use the old rule of promoting chars arguments to ints"
when calling such functions.  You need to use the new definition style,
which looks much like the prototype:


int
addusage(char *name, char type, char *args, char *usage)
{
  ...
}