source: public/doc/gnu-c/Pragma-Basics.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 8.3 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
4
5(The work of Trevis Rothwell and Nelson Beebe has been assigned or
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing GNU and promoting software freedom." -->
19<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
20<head>
21<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22<title>Pragma Basics (GNU C Language Manual)</title>
23
24<meta name="description" content="Pragma Basics (GNU C Language Manual)">
25<meta name="keywords" content="Pragma Basics (GNU C Language Manual)">
26<meta name="resource-type" content="document">
27<meta name="distribution" content="global">
28<meta name="Generator" content="makeinfo">
29<link href="index.html" rel="start" title="Top">
30<link href="Symbol-Index.html" rel="index" title="Symbol Index">
31<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
32<link href="Pragmas.html" rel="up" title="Pragmas">
33<link href="Severity-Pragmas.html" rel="next" title="Severity Pragmas">
34<link href="Pragmas.html" rel="prev" title="Pragmas">
35<style type="text/css">
36<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.no-bullet {list-style: none}
51-->
52</style>
53
54
55</head>
56
57<body lang="en">
58<span id="Pragma-Basics"></span><div class="header">
59<p>
60Next: <a href="Severity-Pragmas.html" accesskey="n" rel="next">Severity Pragmas</a>, Up: <a href="Pragmas.html" accesskey="u" rel="up">Pragmas</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
61</div>
62<hr>
63<span id="Pragma-Basics-1"></span><h4 class="subsection">30.1.1 Pragma Basics</h4>
64
65<p>C defines two syntactical forms for pragmas, the line form and the
66token form. You can write any pragma in either form, with the same
67meaning.
68</p>
69<p>The line form is a line in the source code, like this:
70</p>
71<div class="example">
72<pre class="example">#pragma <var>line</var>
73</pre></div>
74
75<p>The line pragma has no effect on the parsing of the lines around it.
76This form has the drawback that it can&rsquo;t be generated by a macro expansion.
77</p>
78<p>The token form is a series of tokens; it can appear anywhere in the
79program between the other tokens.
80</p>
81<div class="example">
82<pre class="example">_Pragma (<var>stringconstant</var>)
83</pre></div>
84
85<p>The pragma has no effect on the syntax of the tokens that surround it;
86thus, here&rsquo;s a pragma in the middle of an <code>if</code> statement:
87</p>
88<div class="example">
89<pre class="example">if _Pragma (&quot;hello&quot;) (x &gt; 1)
90</pre></div>
91
92<p>However, that&rsquo;s an unclear thing to do; for the sake of
93understandability, it is better to put a pragma on a line by itself
94and not embedded in the middle of another construct.
95</p>
96<p>Both forms of pragma have a textual argument. In a line pragma, the
97text is the rest of the line. The textual argument to <code>_Pragma</code>
98uses the same syntax as a C string constant: surround the text with
99two &lsquo;<samp>&quot;</samp>&rsquo; characters, and add a backslash before each &lsquo;<samp>&quot;</samp>&rsquo; or
100&lsquo;<samp>\</samp>&rsquo; character in it.
101</p>
102<p>With either syntax, the textual argument specifies what to do.
103It begins with one or several words that specify the operation.
104If the compiler does not recognize them, it ignores the pragma.
105</p>
106<p>Here are the pragma operations supported in GNU C.
107</p>
108<dl compact="compact">
109<dt><code>#pragma GCC dependency &quot;<var>file</var>&quot; [<var>message</var>]</code></dt>
110<dt><code>_Pragma (&quot;GCC dependency \&quot;<var>file</var>\&quot; [<var>message</var>]&quot;)</code></dt>
111<dd><p>Declares that the current source file depends on <var>file</var>, so GNU C
112compares the file times and gives a warning if <var>file</var> is newer
113than the current source file.
114</p>
115<p>This directive searches for <var>file</var> the way <code>#include</code>
116searches for a non-system header file.
117</p>
118<p>If <var>message</var> is given, the warning message includes that text.
119</p>
120<p>Examples:
121</p>
122<div class="example">
123<pre class="example">#pragma GCC dependency &quot;parse.y&quot;
124_pragma (&quot;GCC dependency \&quot;/usr/include/time.h\&quot; \
125rerun fixincludes&quot;)
126</pre></div>
127
128</dd>
129<dt><code>#pragma GCC poison <var>identifiers</var></code></dt>
130<dt><code>_Pragma (&quot;GCC poison <var>identifiers</var>&quot;)</code></dt>
131<dd><p>Poisons the identifiers listed in <var>identifiers</var>.
132</p>
133<p>This is useful to make sure all mention of <var>identifiers</var> has been
134deleted from the program and that no reference to them creeps back in.
135If any of those identifiers appears anywhere in the source after the
136directive, it causes a compilation error. For example,
137</p>
138<div class="example">
139<pre class="example">#pragma GCC poison printf sprintf fprintf
140sprintf(some_string, &quot;hello&quot;);
141</pre></div>
142
143<p>generates an error.
144</p>
145<p>If a poisoned identifier appears as part of the expansion of a macro
146that was defined before the identifier was poisoned, it will <em>not</em>
147cause an error. Thus, system headers that define macros that use
148the identifier will not cause errors.
149</p>
150<p>For example,
151</p>
152<div class="example">
153<pre class="example">#define strrchr rindex
154_Pragma (&quot;GCC poison rindex&quot;)
155strrchr(some_string, 'h');
156</pre></div>
157
158<p>does not cause a compilation error.
159</p>
160</dd>
161<dt><code>#pragma GCC system_header</code></dt>
162<dt><code>_Pragma (&quot;GCC system_header&quot;)</code></dt>
163<dd><p>Specify treating the rest of the current source file as if it came
164from a system header file. See <a href="https://gcc.gnu.org/onlinedocs/gcc/System-Headers.html#System-Headers">System Headers</a> in <cite>Using the GNU Compiler Collection</cite>.
165</p>
166</dd>
167<dt><code>#pragma GCC warning <var>message</var></code></dt>
168<dt><code>_Pragma (&quot;GCC warning <var>message</var>&quot;)</code></dt>
169<dd><p>Equivalent to <code>#warning</code>. Its advantage is that the
170<code>_Pragma</code> form can be included in a macro definition.
171</p>
172</dd>
173<dt><code>#pragma GCC error <var>message</var></code></dt>
174<dt><code>_Pragma (&quot;GCC error <var>message</var>&quot;)</code></dt>
175<dd><p>Equivalent to <code>#error</code>. Its advantage is that the
176<code>_Pragma</code> form can be included in a macro definition.
177</p>
178</dd>
179<dt><code>#pragma GCC message <var>message</var></code></dt>
180<dt><code>_Pragma (&quot;GCC message <var>message</var>&quot;)</code></dt>
181<dd><p>Similar to &lsquo;<samp>GCC warning</samp>&rsquo; and &lsquo;<samp>GCC error</samp>&rsquo;, this simply prints an
182informational message, and could be used to include additional warning
183or error text without triggering more warnings or errors. (Note that
184unlike &lsquo;<samp>warning</samp>&rsquo; and &lsquo;<samp>error</samp>&rsquo;, &lsquo;<samp>message</samp>&rsquo; does not include
185&lsquo;<samp>GCC</samp>&rsquo; as part of the pragma.)
186</p></dd>
187</dl>
188
189<hr>
190<div class="header">
191<p>
192Next: <a href="Severity-Pragmas.html" accesskey="n" rel="next">Severity Pragmas</a>, Up: <a href="Pragmas.html" accesskey="u" rel="up">Pragmas</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
193</div>
194
195
196
197</body>
198</html>
Note: See TracBrowser for help on using the repository browser.