diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/preprocessor%2Ferror.html | |
new repository
Diffstat (limited to 'devdocs/c/preprocessor%2Ferror.html')
| -rw-r--r-- | devdocs/c/preprocessor%2Ferror.html | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/devdocs/c/preprocessor%2Ferror.html b/devdocs/c/preprocessor%2Ferror.html new file mode 100644 index 00000000..decd26b2 --- /dev/null +++ b/devdocs/c/preprocessor%2Ferror.html @@ -0,0 +1,37 @@ + <h1 id="firstHeading" class="firstHeading">Diagnostic directives</h1> <p>Shows the given error message and renders the program ill-formed<span class="t-rev-inl t-since-c23"><span>, or given warning message without affect the validity of the program</span><span><span class="t-mark-rev t-since-c23">(since C23)</span></span></span>.</p> +<h3 id="Syntax"> Syntax</h3> <table class="t-sdsc-begin"> <tr class="t-sdsc"> <td> <code>#error</code> <span class="t-spar">diagnostic-message</span> </td> <td> (1) </td> <td class="t-sdsc-nopad"> </td> +</tr> <tr class="t-sdsc"> <td> <code>#warning</code> <span class="t-spar">diagnostic-message</span> </td> <td> (2) </td> <td> <span class="t-mark-rev t-since-c23">(since C23)</span> </td> +</tr> +</table> <h3 id="Explanation"> Explanation</h3> <div class="t-li1"> +<span class="t-li">1)</span> After encountering the <code>#error</code> directive, an implementation displays the message <span class="t-spar">diagnostic-message</span> and renders the program ill-formed (the compilation stops).</div> <div class="t-li1"> +<span class="t-li">2)</span> Same as <span class="t-v">(1)</span>, except that the validity of the program is not affected and the compilation continues. </div> <p><span class="t-spar">diagnostic-message</span> can consist of several words not necessarily in quotes.</p> +<h3 id="Notes"> Notes</h3> <p>Before its standardization in C23, <code>#warning</code> has been provided by many compilers in all modes as a conforming extension.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#if __STDC__ != 1 +# error "Not a standard compliant compiler" +#endif + +#if __STDC_VERSION__ >= 202311L +# warning "Using #warning as a standard feature" +#endif + +#include <stdio.h> +int main (void) +{ + printf("The compiler used conforms to the ISO C Standard !!"); +}</pre></div> <p>Possible output:</p> +<div class="text source-text"><pre data-language="c">The compiler used conforms to the ISO C Standard !!</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C17 standard (ISO/IEC 9899:2018): </li> +<ul><li> 6.10.5 Error directive (p: 126-127) </li></ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 6.10.5 Error directive (p: 174) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 6.10.5 Error directive (p: 159) </li></ul> +<li> C89/C90 standard (ISO/IEC 9899:1990): </li> +<ul><li> 3.8.5 Error directive </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/preprocessor/error" title="cpp/preprocessor/error">C++ documentation</a></span> for <span class=""><span>Diagnostic directives</span></span> </td> +</tr> </table> <div class="_attribution"> + <p class="_attribution-p"> + © cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br> + <a href="https://en.cppreference.com/w/c/preprocessor/error" class="_attribution-link">https://en.cppreference.com/w/c/preprocessor/error</a> + </p> +</div> |
