![]() |
![]() |
1510 | ![]() |
||||
![]() | |||||||
| 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;
}
MISRA C:2012 Rules applicable to message 1510:
| Rule-1.3 (Required) | There shall be no occurrence of undefined or critical unspecified behaviour |
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 |