Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Changed MISRA 2004 to 2012, but no rule is cited here--the entry can probably be deleted

...

This noncompliant code example omits the type specifier.:

Code Block
bgColor#FFCCCC
langc
extern foo;

...

This compliant solution explicitly includes a type specifier.:

Code Block
bgColor#ccccff
langc
extern int foo;

...

However, to conform with the C Standard, you must explicitly prototype every function before invoking it. This noncompliant example fails to prototype the foo() function before invoking it in main().:

Code Block
bgColor#FFCCCC
langc
int main(void) {
  int c = foo();
  printf("%d\n", c);
  return 0;
}

int foo(int a) {
  return a;
}

...

In this compliant solution, a prototype for foo() appears before the function invocation.:

Code Block
bgColor#ccccff
langc
int foo(int);

int main(void) {
  int c = foo(0);
  printf("%d\n", c);
  return 0;
}

int foo(int a) {
  return a;
}

...

This compliant solution explicitly defines the return type of foo() as unsigned int.:

Code Block
bgColor#ccccff
langc
unsigned int foo(void) {
  return UINT_MAX;
}

int main(void) {
  long long c = foo();
  printf("%lld\n", c);
  return 0;
}

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

 

ECLAIR

Include Page
ECLAIR_V
ECLAIR_V

decltype

Fully implemented.

GCC

Include Page
GCC_V
GCC_V

 

Can detect violations of this rule when the -Wimplicit and -Wreturn-type flags are used.

Klocwork

Include Page
Klocwork_V
Klocwork_V

IF_MISS_DECL RETVOID.IMPLICIT

 

LDRA tool suite

Include Page
LDRA_V
LDRA_V

24 D
20 S
326 S

Fully implemented.

PRQA QA-C
Include Page
PRQA_V
PRQA_V

0434 (C)
1302
2050
2051
3335

Fully implemented.

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

...

ISO/IEC TR 24772:2013Subprogram Signature Mismatch [OTR]
MISRA - C:2012 

Bibliography

[ISO/IEC 9899:2011]Section 6.7.2, "Type Specifiers"
[Jones 2008] 

...