G
Gary
I recently joined a project with a mix of K&R C and ANSI C++. There are
instances
of prototype mismatches defined in one file and used in another that aren't
being caught and result in run time errors (see example below).
Is there a utility that can catch such mismatches (e.g. lint or something)?
I'm constrained in that I'm not allowed to make massive code changes.
Thanks in advance,
Gary
/********** file1.c ***************/
/* defines a function with two args */
extern int add();
int add(x, y)
int x;
int y;
{
return x+y;
}
/********** file2.C ***************/
/* programmer introduces bug by declaring prototype
with one arg instead of two. */
extern "C" int add(int x);
int main(int argc, char* argv[])
{
int z = add(3); /* <-- incorrect signature not caught by linker */
return 0;
}
instances
of prototype mismatches defined in one file and used in another that aren't
being caught and result in run time errors (see example below).
Is there a utility that can catch such mismatches (e.g. lint or something)?
I'm constrained in that I'm not allowed to make massive code changes.
Thanks in advance,
Gary
/********** file1.c ***************/
/* defines a function with two args */
extern int add();
int add(x, y)
int x;
int y;
{
return x+y;
}
/********** file2.C ***************/
/* programmer introduces bug by declaring prototype
with one arg instead of two. */
extern "C" int add(int x);
int main(int argc, char* argv[])
{
int z = add(3); /* <-- incorrect signature not caught by linker */
return 0;
}