![]() |
![]() |
1512 | ![]() |
||||
![]() | |||||||
| 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;
}
No MISRA C:2012 Rules applicable to message 1512
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |