C preprocessor: Difference between revisions

Content deleted Content added
No edit summary
Line 276:
#endif
</syntaxhighlight>
 
;=== Warning ===
As of [[C23 (C standard revision)|C23]]<ref name="N3096">{{cite web |title=WG14-N3096 : Draft for ISO/IEC 9899:2023 |url=https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf |website=open-std.org |archive-url=https://web.archive.org/web/20230402172459/https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf |archive-date=2 April 2023 |date=1 April 2023 |url-status=live}}</ref> and [[C++23]]<ref>{{Cite web|title=Working Draft, Standard for Programming Language C++|url=https://open-std.org/JTC1/SC22/WG21/docs/papers/2023/n4944.pdf|date=2023-03-22}}</ref>, standardizea {{code|lang=c|#warning}}directive to print a message without aborting is provided. Some typical uses are to warn about the use of [[deprecated]] functionality. For example:
 
<syntaxhighlight lang="c">
// GNU, Intel and IBM
#warning "Do not use ABC, which is deprecated. Use XYZ instead."
</syntaxhighlight>
 
<syntaxhighlight lang="c">
// Microsoft
#pragma message("Do not use ABC, which is deprecated. Use XYZ instead.")
</syntaxhighlight>
 
Prior to C23 and C++23, this directive existed in many compilers as a non-standard feature, such as the C compilers by GNU, Intel, Microsoft and IBM.
 
=== Binary resource inclusion ===
Line 285 ⟶ 300:
==Non-standard features ==
 
;=== Pragma ===
The <code>#pragma</code> directive is defined by standard languages, but with little or no requirements for syntax after its name so that compilers are free to define subsequent syntax and associated behavior. For instance, a pragma is often used to allow suppression of error messages, manage heap and stack debugging and so on.
 
C99 introduced a few standard pragmas, taking the form <code>#pragma STDC ...</code>, which are used to control the floating-point implementation. The alternative, macro-like form {{code|_Pragma(...)}} was also added.
 
;=== Trigraphs ===
Many implementations do not support trigraphs or do not replace them by default.
 
;=== Assertion ===
;Warning
Many implementations (such as the C compilers by GNU, Intel, Microsoft and IBM) provide a non-standard directive to print a message without aborting, typically to warn about the use of [[deprecated]] functionality. For example:
 
<syntaxhighlight lang="c">
// GNU, Intel and IBM
#warning "Do not use ABC, which is deprecated. Use XYZ instead."
</syntaxhighlight>
 
<syntaxhighlight lang="c">
// Microsoft
#pragma message("Do not use ABC, which is deprecated. Use XYZ instead.")
</syntaxhighlight>
 
[[C23 (C standard revision)|C23]]<ref name="N3096">{{cite web |title=WG14-N3096 : Draft for ISO/IEC 9899:2023 |url=https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf |website=open-std.org |archive-url=https://web.archive.org/web/20230402172459/https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf |archive-date=2 April 2023 |date=1 April 2023 |url-status=live}}</ref> and [[C++23]]<ref>{{Cite web|title=Working Draft, Standard for Programming Language C++|url=https://open-std.org/JTC1/SC22/WG21/docs/papers/2023/n4944.pdf|date=2023-03-22}}</ref> standardize {{code|lang=c|#warning}}.
 
;Assertion
Some [[Unix]] preprocessors provided an [[assertion (computing)|assertion]] feature {{endash}} which has little similarity to standard library assertions.<ref>[https://gcc.gnu.org/onlinedocs/cpp/Obsolete-Features.html GCC Obsolete features]</ref>
 
;=== Include next ===
GCC provides <code>#include_next</code> for chaining headers of the same name.<ref>{{Cite web|url=https://gcc.gnu.org/onlinedocs/cpp/Wrapper-Headers.html|title = Wrapper Headers (The C Preprocessor)}}</ref>
 
;=== Import ===
Unlike C and C++, Objective-C includes an <code>#import</code> directive that is like <code>#include</code> but results in a file being included only once {{endash}} eliminating the need for include guards and [[pragma once|<code>#pragma once</code>]].
 
In [[Microsoft Visual C++]] (MSVC), there also exists aan <code>#import</code> preprocessor directive, used to import type libraries.<ref>{{Cite web|url=https://learn.microsoft.com/en-us/cpp/preprocessor/hash-import-directive-cpp|title = #import directive (C++)}}</ref> It is a nonstandard directive.
 
The Objective-C directive should not be confused with the C++ keyword <code>import</code>, which is used to import C++ [[Precompiled header#Modules|modules]] (since [[C++20]]), and is not a preprocessor directive.