Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / mingw / info / gdb / C-Operators.html
blobb00bbe1cecf87338c3e814c13734557437511720
1 <html lang="en">
2 <head>
3 <title>Debugging with GDB</title>
4 <meta http-equiv="Content-Type" content="text/html">
5 <meta name="description" content="Debugging with GDB">
6 <meta name="generator" content="makeinfo 4.3">
7 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
8 </head>
9 <body>
10 <div class="node">
11 <p>
12 Node:<a name="C%20Operators">C Operators</a>,
13 Next:<a rel="next" accesskey="n" href="C-Constants.html#C%20Constants">C Constants</a>,
14 Up:<a rel="up" accesskey="u" href="C.html#C">C</a>
15 <hr><br>
16 </div>
18 <h5 class="subsubsection">C and C<tt>++</tt> operators</h5>
20 <p>Operators must be defined on values of specific types. For instance,
21 <code>+</code> is defined on numbers, but not on structures. Operators are
22 often defined on groups of types.
24 <p>For the purposes of C and C<tt>++</tt>, the following definitions hold:
26 <ul>
28 <li><em>Integral types</em> include <code>int</code> with any of its storage-class
29 specifiers; <code>char</code>; <code>enum</code>; and, for C<tt>++</tt>, <code>bool</code>.
31 <li><em>Floating-point types</em> include <code>float</code>, <code>double</code>, and
32 <code>long double</code> (if supported by the target platform).
34 <li><em>Pointer types</em> include all types defined as <code>(</code><var>type</var><code> *)</code>.
36 <li><em>Scalar types</em> include all of the above.
38 </ul>
40 <p>The following operators are supported. They are listed here
41 in order of increasing precedence:
43 <dl>
44 <dt><code>,</code>
45 <dd>The comma or sequencing operator. Expressions in a comma-separated list
46 are evaluated from left to right, with the result of the entire
47 expression being the last expression evaluated.
49 <br><dt><code>=</code>
50 <dd>Assignment. The value of an assignment expression is the value
51 assigned. Defined on scalar types.
53 <br><dt><code></code><var>op</var><code>=</code>
54 <dd>Used in an expression of the form <code></code><var>a</var><code>&nbsp;</code><var>op</var><code>=&nbsp;</code><var>b</var><code></code>,
55 and translated to <code></code><var>a</var><code>&nbsp;=&nbsp;</code><var>a&nbsp;op&nbsp;b</var><code></code>.
56 <code></code><var>op</var><code>=</code> and <code>=</code> have the same precedence.
57 <var>op</var> is any one of the operators <code>|</code>, <code>^</code>, <code>&amp;</code>,
58 <code>&lt;&lt;</code>, <code>&gt;&gt;</code>, <code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>%</code>.
60 <br><dt><code>?:</code>
61 <dd>The ternary operator. <code></code><var>a</var><code> ? </code><var>b</var><code> : </code><var>c</var><code></code> can be thought
62 of as: if <var>a</var> then <var>b</var> else <var>c</var>. <var>a</var> should be of an
63 integral type.
65 <br><dt><code>||</code>
66 <dd>Logical <small>OR</small>. Defined on integral types.
68 <br><dt><code>&amp;&amp;</code>
69 <dd>Logical <small>AND</small>. Defined on integral types.
71 <br><dt><code>|</code>
72 <dd>Bitwise <small>OR</small>. Defined on integral types.
74 <br><dt><code>^</code>
75 <dd>Bitwise exclusive-<small>OR</small>. Defined on integral types.
77 <br><dt><code>&amp;</code>
78 <dd>Bitwise <small>AND</small>. Defined on integral types.
80 <br><dt><code>==</code>, <code>!=</code>
81 <dd>Equality and inequality. Defined on scalar types. The value of these
82 expressions is 0 for false and non-zero for true.
84 <br><dt><code>&lt;</code>, <code>&gt;</code>, <code>&lt;=</code>, <code>&gt;=</code>
85 <dd>Less than, greater than, less than or equal, greater than or equal.
86 Defined on scalar types. The value of these expressions is 0 for false
87 and non-zero for true.
89 <br><dt><code>&lt;&lt;</code>, <code>&gt;&gt;</code>
90 <dd>left shift, and right shift. Defined on integral types.
92 <br><dt><code>@</code>
93 <dd>The GDB "artificial array" operator (see <a href="Expressions.html#Expressions">Expressions</a>).
95 <br><dt><code>+</code>, <code>-</code>
96 <dd>Addition and subtraction. Defined on integral types, floating-point types and
97 pointer types.
99 <br><dt><code>*</code>, <code>/</code>, <code>%</code>
100 <dd>Multiplication, division, and modulus. Multiplication and division are
101 defined on integral and floating-point types. Modulus is defined on
102 integral types.
104 <br><dt><code>++</code>, <code>--</code>
105 <dd>Increment and decrement. When appearing before a variable, the
106 operation is performed before the variable is used in an expression;
107 when appearing after it, the variable's value is used before the
108 operation takes place.
110 <br><dt><code>*</code>
111 <dd>Pointer dereferencing. Defined on pointer types. Same precedence as
112 <code>++</code>.
114 <br><dt><code>&amp;</code>
115 <dd>Address operator. Defined on variables. Same precedence as <code>++</code>.
117 <p>For debugging C<tt>++</tt>, GDB implements a use of <code>&amp;</code> beyond what is
118 allowed in the C<tt>++</tt> language itself: you can use <code>&amp;(&amp;</code><var>ref</var><code>)</code>
119 (or, if you prefer, simply <code>&amp;&amp;</code><var>ref</var><code></code>) to examine the address
120 where a C<tt>++</tt> reference variable (declared with <code>&amp;</code><var>ref</var><code></code>) is
121 stored.
123 <br><dt><code>-</code>
124 <dd>Negative. Defined on integral and floating-point types. Same
125 precedence as <code>++</code>.
127 <br><dt><code>!</code>
128 <dd>Logical negation. Defined on integral types. Same precedence as
129 <code>++</code>.
131 <br><dt><code>~</code>
132 <dd>Bitwise complement operator. Defined on integral types. Same precedence as
133 <code>++</code>.
135 <br><dt><code>.</code>, <code>-&gt;</code>
136 <dd>Structure member, and pointer-to-structure member. For convenience,
137 GDB regards the two as equivalent, choosing whether to dereference a
138 pointer based on the stored type information.
139 Defined on <code>struct</code> and <code>union</code> data.
141 <br><dt><code>.*</code>, <code>-&gt;*</code>
142 <dd>Dereferences of pointers to members.
144 <br><dt><code>[]</code>
145 <dd>Array indexing. <code></code><var>a</var><code>[</code><var>i</var><code>]</code> is defined as
146 <code>*(</code><var>a</var><code>+</code><var>i</var><code>)</code>. Same precedence as <code>-&gt;</code>.
148 <br><dt><code>()</code>
149 <dd>Function parameter list. Same precedence as <code>-&gt;</code>.
151 <br><dt><code>::</code>
152 <dd>C<tt>++</tt> scope resolution operator. Defined on <code>struct</code>, <code>union</code>,
153 and <code>class</code> types.
155 <br><dt><code>::</code>
156 <dd>Doubled colons also represent the GDB scope operator
157 (see <a href="Expressions.html#Expressions">Expressions</a>). Same precedence as <code>::</code>,
158 above.
159 </dl>
161 <p>If an operator is redefined in the user code, GDB usually
162 attempts to invoke the redefined version instead of using the operator's
163 predefined meaning.
165 <ul class="menu">
166 <li><a accesskey="1" href="C-Constants.html#C%20Constants">C Constants</a>:
167 </ul>
169 </body></html>