MISRAC2012-Rule-23.4
In this section:
Synopsis
(Advisory) A generic association shall list an appropriate type.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Found generic association with inappropriate type.
Coding standards
- MISRA C:2012 Rule-23.4
(Required) A generic association shall list an appropriate type
Code examples
The following code example fails the check and will give a warning:
typedef int Array [10];
typedef Array * ArrayP;
void handle_intp(int* x);
/* Non-compliant (because Array is listed) */
#define handle_array_nc(X) _Generic(&(X[0]) \
, Array : handle_intp (&(X[0])) \
, ArrayP : handle_intp (X) \
, int *: handle_intp (X) )
void example(void) {
Array arr;
handle_array_nc(arr);
}
The following code example passes the check and will not give a warning about this issue:
typedef int Array [10];
typedef Array * ArrayP;
void handle_intp(int* x);
/* Compliant */
#define handle_array(X) _Generic( &(X[0]) \
, int *: handle_intp (X) \
, ArrayP : handle_intp (X) )
void example(void) {
Array arr;
handle_array(arr);
}