Diagnostic 1782: #pragma once is obsolete. Use #ifndef guard instead.

Diagnostic 1782: #pragma once is obsolete. Use #ifndef guard instead.

Thank you for your interest in this diagnostic message. We are still in the process of documenting this specific diagnostic.

Please let us know of your experience with this diagnostic message by posting a comment below. Your interest in this diagnostic will help us prioritize the order we document diagnostics.

For more complete information about compiler optimizations, see our Optimization Notice.

4 comments

Top
Jennifer J. (Intel)'s picture

You should not see the warning/remark by default in the Intel C++ Compiler.
#pragma once should continue to work (Currently NOT deprecated) with the Intel Compiler.

Kittur Ganesh (Intel)'s picture

Hi kfsone,
Gcc used to warn by default and I believe they were planning to deprecate/remove the feature, but perhaps they were overruled by their users

Anyways, I touched base with our compiler developers also especially on your comment also. In summary, you should not see the warning/remark by default in ICC, and #pragma once should continue to work indefinitely. Depending on your development context and portability considerations etc., you can yes safely disable or ignore the warning too.

BTW, per our developers, there shouldn't be any significant compilation-speed difference between #pragma once and the #ifndef idiom. The FE looks to see if an include file uses the #ifndef idiom, and if so, it is marked in pretty much the same way as one that contains #pragma once.

Some useful links to ponder on this (below)
See http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/Obsolete-once-only-headers.html
and http://en.wikipedia.org/wiki/Pragma_once

Also, I am in touch with the developers to see if the message we output in ICC and will keep you posted.

kfsone's picture

(Also note that GCC un-deprecated #pragma once)

kfsone's picture

Ugh. Thank goodness for -wd1782.

The downside to #pragma guard in a very large project is precompiler namespace pollution. We have over 1500 header files... #pragma once under GCC and MSVC provides a small but appreciated compile time improvement.

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.