Unicorn with delicious cookie
Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2641. MISRA. Types should be explicitl…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C++)
OWASP errors (C#)
OWASP errors (Java)
Problems related to code analyzer
Additional information
toggle menu Contents

V2641. MISRA. Types should be explicitly specified.

Apr 04 2025

This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.

This diagnostic rule is relevant only for C.

The C language enables the declaration of entities without explicitly specifying their type. In such a case, the standard states that the entity type is int. Using such a language feature can lead to confusion or an error.

The example:

// TU1.c
#include <stddef.h>
void *my_malloc (size_t n) { /* Implementation */ }

// TU2.c
#include <stddef.h>

extern my_malloc (size_t n);

In the TU1.c file, the my_malloc allocating function, which takes a size in bytes and returns a pointer to the allocated memory is defined. To use this function, developers manually wrote a forward function declaration in the TU2.c file but forgot to specify the return type. As a result, the compiler assumes that the function returns int. This may cause errors during program execution if the pointer size and int size do not match.

To fix the error, specify the data type:

// TU2.c
#include <stddef.h>

extern void *my_malloc (size_t n);

The analyzer also issues warnings on the following entity declarations:

extern var1; // variable declaration of 'int' type
func1() {}   // function declaration with the no return type
static var2; // variable declaration of 'double' type

The fixed examples:

extern int var1;    // variable declaration of 'int' type
void func1() {}     // function declaration with the no return type
static double var2; // variable declaration of 'double' type

This diagnostic is classified as:

  • MISRA-C-8.1
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I want to join the test
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam