Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.DECL.NO_TYPE

Declaration without a type.

MISRA C 2012 Rule 8.1: Types shall be explicitly specified

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90

Rationale

The C90 standard permits types to be omitted in some circumstances, in which case the int type is implicitly specified. Examples of the circumstances in which an implicit int might be used are:

  • Object declarations;
  • Parameter declarations;
  • Member declarations;
  • typedef declarations;
  • Function return types.

The omission of an explicit type might lead to confusion. For example, in the declaration:

extern void g ( char c, const k );

the type of k is const int whereas const char might have been expected.

Example

The following examples show compliant and non-compliant object declarations:

extern         x;           /* Non-compliant - implicit int type */ 
extern int16_t x;           /* Compliant - explicit type         */ 
const          y;           /* Non-compliant - implicit int type */ 
const int16_t  y;           /* Compliant - explicit type         */

The following examples show compliant and non-compliant function type declarations:

extern f ( void );                         /* Non-compliant - implicit
                                            * int return type           */ 
extern int16_t f ( void );                 /* Compliant                 */

extern void g ( char c, const k );         /* Non-compliant - implicit
                                            * int for parameter k       */ 
extern void g ( char c, const int16_t k ); /* Compliant                 */

The following examples show compliant and non-compliant type definitions:

typedef ( *pfi ) ( void );                 /* Non-compliant - implicit int
                                            * return type                   */ 
typedef int16_t ( *pfi ) ( void );         /* Compliant                     */ 
typedef void ( *pfv ) (const x );          /* Non-compliant - implicit int
                                            * for parameter x               */ 
typedef void ( *pfv ) ( int16_t x );       /* Compliant                     */

The following examples show compliant and non-compliant member declarations:

struct str 
{
  int16_t x;        /* Compliant                                 */ 
  const y;          /* Non-compliant - implicit int for member y */ 
} s;

See also

Rule 8.2

MISRA-C 2004 Rule 8.2 (required): Whenever an object or function is declared or defined, its type shall be explicitly stated

Example

extern         x;          /* Non-compliant - implicit int type */
extern int16_t x;          /* Compliant - explicit type         */
const          y;          /* Non-compliant - implicit int type */
const int16_t  y;          /* Compliant - explicit type         */
static         foo(void);  /* Non-compliant - implicit type     */
static int16_t foo(void);  /* Compliant - explicit type         */