﻿# V2639\. MISRA\. Default association should appear as either the first or the last association of a generic selection\.

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

This diagnostic rule is relevant only for C\.

Default association declared with the `default` keyword should be placed either first or last in the [`_Generic`](https://en.cppreference.com/w/c/language/generic) selection \(C11\)\. This structure enhances code readability for developers\.

The example:

```cpp
#define abs(Y)( _Generic( (Y)        \
              , long     : labs     \
              , default  : abs      \
              , long long: llabs)(Y))

long foo(long x)
{
  return abs(x);   
}
```

The `default` association is placed between `int` and `char`\. This ordering of the association list complicates the `_Generic` construction\.

The fixed code:

```cpp
// First option
#define abs(Y)( _Generic( (Y)        \
              , default  : abs      \
              , long     : labs     \
              , long long: llabs)(Y))

// Second option
#define abs(Y)( _Generic( (Y)      \
              , long     : labs   \
              , long long: llabs  \
              , default  : abs)(Y))

long foo(long x)
{
  return abs(x);   
}
```