Main Content

AUTOSAR C++14 Rule A16-7-1

The #pragma directive shall not be used

Description

Rule Definition

The #pragma directive shall not be used.

Rationale

The use of the #pragma directive in your code results in implementation-defined behavior. The directive might also not be supported by certain compilers.

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

//header.h
#pragma once //Noncompliant

#ifndef HEADER_H_ //Compliant
#define HEADER_H_
// ...
// body of header file
//..
#endif

The #pragma once directive prevents the inclusion of header.h more than once. However, if you copy header.h into multiple project modules, the directive may or may not treat the copies as the same file depending on the implementation. To avoid double definitions, use the #ifndef include guard instead.

Check Information

Group: 16 Preprocessing Directives
Category: Required, Automated

Version History

Introduced in R2019b