[previous] 1512 [next] Identifier 'name' with external linkage has separate declarations in multiple translation units.
CMA maintenance checks

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

Maintenance of a project may require changes to the types of functions or objects. When such maintenance takes place, it is important that all declarations are updated correctly. Accordingly, the more declarations for a single name, the more chance that one will be missed during maintenance.

Example:


// TU1.cpp
int foo(int);

// TU2.cpp
int foo(int);

void bar()
{
  int i = foo(10);
}

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

Maintenance requires that the function returns void, so a change is made. 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