Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
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.

04 Avr 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

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam