[previous] 1510 [next] 'name' has external linkage and has incompatible declarations.
CMA undefined

In a linkable program, only one definition of a function or object is allowed. Where several declarations for the same name have external linkage, all declarations must be compatible.

In every declaration for an object the type must be the same. In C++, every declaration for a function with a given set of arguments cannot differ in return type, linkage or exception specification. In C all functions must be declared with the same parameter and return types.

Example:


// TU1.cpp
extern int i

void foo(int);

// TU2.cpp
float i = 0.0;    // ERROR: incompatible declaration for 'i'

int foo(int);     // ERROR: incompatible declaration for 'foo'

Linkers in general only consider names, they will not warn that the return type of the function is different in a different translation unit, and so this may be the cause of hard to find errors in a program.

Example;


// TU1.cpp
void foo(int);

// TU2.cpp
int foo(int);          // ERROR: Declaration for 'foo' was not updated.

void bar ()
{
  int i = foo(10);     // ERROR: foo no longer returns a value
}

// TU3.cpp
void foo(int)
{
  return;
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents