summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/qualifiers-implementation.html
blob: 971c61b3672410b4b78ebd64cfe94a4397033041 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
<div class="section-level-extent" id="Qualifiers-implementation"> <div class="nav-panel"> <p> Next: <a href="declarators-implementation" accesskey="n" rel="next">Declarators</a>, Previous: <a href="structures-unions-enumerations-and-bit-fields-implementation" accesskey="p" rel="prev">Structures, Unions, Enumerations, and Bit-Fields</a>, Up: <a href="c-implementation" accesskey="u" rel="up">C Implementation-Defined Behavior</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="Qualifiers"><span>4.10 Qualifiers<a class="copiable-link" href="#Qualifiers"> ¶</a></span></h1> <ul class="itemize mark-bullet"> <li>What constitutes an access to an object that has volatile-qualified type (C90 6.5.3, C99 and C11 6.7.3). <p>Such an object is normally accessed by pointers and used for accessing hardware. In most expressions, it is intuitively obvious what is a read and what is a write. For example </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">volatile int *dst = <var class="var">somevalue</var>;
volatile int *src = <var class="var">someothervalue</var>;
*dst = *src;</pre>
</div> <p>will cause a read of the volatile object pointed to by <var class="var">src</var> and store the value into the volatile object pointed to by <var class="var">dst</var>. There is no guarantee that these reads and writes are atomic, especially for objects larger than <code class="code">int</code>. </p> <p>However, if the volatile storage is not being modified, and the value of the volatile storage is not used, then the situation is less obvious. For example </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">volatile int *src = <var class="var">somevalue</var>;
*src;</pre>
</div> <p>According to the C standard, such an expression is an rvalue whose type is the unqualified version of its original type, i.e. <code class="code">int</code>. Whether GCC interprets this as a read of the volatile object being pointed to or only as a request to evaluate the expression for its side effects depends on this type. </p> <p>If it is a scalar type, or on most targets an aggregate type whose only member object is of a scalar type, or a union type whose member objects are of scalar types, the expression is interpreted by GCC as a read of the volatile object; in the other cases, the expression is only evaluated for its side effects. </p> <p>When an object of an aggregate type, with the same size and alignment as a scalar type <code class="code">S</code>, is the subject of a volatile access by an assignment expression or an atomic function, the access to it is performed as if the object’s declared type were <code class="code">volatile S</code>. </p> </li>
</ul> </div>  <div class="nav-panel"> <p> Next: <a href="declarators-implementation">Declarators</a>, Previous: <a href="structures-unions-enumerations-and-bit-fields-implementation">Structures, Unions, Enumerations, and Bit-Fields</a>, Up: <a href="c-implementation">C Implementation-Defined Behavior</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">
    &copy; 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/Qualifiers-implementation.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Qualifiers-implementation.html</a>
  </p>
</div>