diff options
| author | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-08-14 22:58:58 -0500 |
| commit | 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 (patch) | |
| tree | 158cfc17b2f644a10f063cb546752cfaae12c97f /devdocs/gcc~13/cast-to-union.html | |
| parent | 9278ddd4ea1a8b1a4c1edaa8894516e3f48d245b (diff) | |
| download | dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.tar.gz dotemacs-82ba818ff456bcd6d56a06226e3f27e98fbb55c3.zip | |
removing all downloaded devdocs files
Diffstat (limited to 'devdocs/gcc~13/cast-to-union.html')
| -rw-r--r-- | devdocs/gcc~13/cast-to-union.html | 23 |
1 files changed, 0 insertions, 23 deletions
diff --git a/devdocs/gcc~13/cast-to-union.html b/devdocs/gcc~13/cast-to-union.html deleted file mode 100644 index db9be2ba..00000000 --- a/devdocs/gcc~13/cast-to-union.html +++ /dev/null @@ -1,23 +0,0 @@ -<div class="section-level-extent" id="Cast-to-Union"> <div class="nav-panel"> <p> Next: <a href="mixed-labels-and-declarations" accesskey="n" rel="next">Mixed Declarations, Labels and Code</a>, Previous: <a href="case-ranges" accesskey="p" rel="prev">Case Ranges</a>, Up: <a href="c-extensions" accesskey="u" rel="up">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="section" id="Cast-to-a-Union-Type"><span>6.31 Cast to a Union Type<a class="copiable-link" href="#Cast-to-a-Union-Type"> ¶</a></span></h1> <p>A cast to a union type is a C extension not available in C++. It looks just like ordinary casts with the constraint that the type specified is a union type. You can specify the type either with the <code class="code">union</code> keyword or with a <code class="code">typedef</code> name that refers to a union. The result of a cast to a union is a temporary rvalue of the union type with a member whose type matches that of the operand initialized to the value of the operand. The effect of a cast to a union is similar to a compound literal except that it yields an rvalue like standard casts do. See <a class="xref" href="compound-literals">Compound Literals</a>. </p> <p>Expressions that may be cast to the union type are those whose type matches at least one of the members of the union. Thus, given the following union and variables: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">union foo { int i; double d; }; -int x; -double y; -union foo z;</pre> -</div> <p>both <code class="code">x</code> and <code class="code">y</code> can be cast to type <code class="code">union foo</code> and the following assignments </p> -<div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">z = (union foo) x; -z = (union foo) y;</pre> -</div> <p>are shorthand equivalents of these </p> -<div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">z = (union foo) { .i = x }; -z = (union foo) { .d = y };</pre> -</div> <p>However, <code class="code">(union foo) FLT_MAX;</code> is not a valid cast because the union has no member of type <code class="code">float</code>. </p> <p>Using the cast as the right-hand side of an assignment to a variable of union type is equivalent to storing in a member of the union with the same type </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">union foo u; -/* <span class="r">…</span> */ -u = (union foo) x ≡ u.i = x -u = (union foo) y ≡ u.d = y</pre> -</div> <p>You can also use the union cast as a function argument: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">void hack (union foo); -/* <span class="r">…</span> */ -hack ((union foo) x);</pre> -</div> </div> <div class="nav-panel"> <p> Next: <a href="mixed-labels-and-declarations">Mixed Declarations, Labels and Code</a>, Previous: <a href="case-ranges">Case Ranges</a>, Up: <a href="c-extensions">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution"> - <p class="_attribution-p"> - © Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br> - <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Cast-to-Union.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Cast-to-Union.html</a> - </p> -</div> |
