Main Content

MISRA C:2012 Rule 11.10

The _Atomic qualifier shall not be applied to the incomplete type void

Since R2024b

Description

Rule Definition

The _Atomic qualifier shall not be applied to the incomplete type void.1

Rationale

The C standard does not guarantee that the _Atomic void* type has any specific size or alignment requirement. You cannot assume that the size and alignment of any arbitrary type _Atomic T* matches the size and alignment of the _Atomic void* type. Conversion between _Atomic void* and _Atomic T* can result in undefined behavior.

Polyspace Implementation

Polyspace® reports a violation of this rule if you use the _Atomic qualifier on void type objects.

Troubleshooting

If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

In this example, Polyspace reports violations when the _Atomic qualifier is applied to the void type in various circumstances.

#include <stdint.h>

/* typedef */
typedef void _Atomic ttype;              //Noncompliant
typedef _Atomic void* pttype;            //Noncompliant
typedef void _Atomic* (*pfunc) (void);   //Noncompliant
typedef int (*pfunc2) (void _Atomic*);   //Noncompliant

/* Different levels of pointers */
void _Atomic* level1;                    //Noncompliant
void _Atomic** level2;                   //Noncompliant
void _Atomic** const level3;             //Noncompliant
void * levelok;                          //Compliant 
int _Atomic* levelint;                   //Compliant 

/* Function return type */
void _Atomic* func1(void);               //Noncompliant
void _Atomic func11(void){};             //Noncompliant

/* Function parameter */
void func2(void _Atomic* param);         //Noncompliant
void func3(void _Atomic*);               //Noncompliant

Check Information

Group: Pointer type conversions
Category: Required
AGC Category: Required

Version History

Introduced in R2024b


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.