core/com.nokia.carbide.cpp.compiler.doc.user/html/errors/err_suspicious_assgn.htm
author fturovic <frank.turovich@nokia.com>
Mon, 19 Jul 2010 16:13:24 -0500
changeset 1641 2b3996fc09a1
parent 0 fb279309251b
permissions -rw-r--r--
revised x86 compiler dates, graphics, CSS, and release notes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1641
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><html>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     2
<head>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     3
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     4
<meta http-equiv="Content-Style-Type" content="text/css" />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     5
<meta name="LASTUPDATED" content="06/17/05 11:09:43" />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     6
<title>Suspicious Assignments and Incorrect Function Returns</title>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     7
<link rel="StyleSheet" href="../../book.css" type="text/css"/>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     8
</head>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
     9
<body bgcolor="#FFFFFF">
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    10
<h3>Suspicious Assignments and Incorrect Function Returns</h3>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    11
<p>  If you enable the Extended Error Checking setting, the C compiler generates a warning if it encounters one of the following potential problems:</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    12
<ul>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    13
  <li>A non-void function that does not contain a return statement. For example, the source code in Listing 1 generates a warning.</li>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    14
</ul>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    15
<blockquote>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    16
  <div class="listing">
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    17
    <p>Listing 1. Non-void Function with no return Statement</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    18
    <p>main() /* assumed to return int */<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    19
      {<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    20
      printf (&quot;hello world\n&quot;);<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    21
      } /* WARNING: no return statement */<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    22
      Listing 6.8 does not generate a warning.<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    23
      Listing 6.8 Explicitly Specifying a Function&rsquo;s void Return Type<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    24
      void main() /* function declared to return void */<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    25
      {<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    26
      printf (&quot;hello world\n&quot;);<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    27
      }<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    28
    </p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    29
  </div>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    30
</blockquote>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    31
<ul>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    32
  <li>An integer or floating-point value assigned to an enum type. Listing 2 shows an example.
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    33
  </li>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    34
</ul>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    35
<blockquote>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    36
  <div class="listing">
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    37
    <h5>Listing 2. Assigning to an Enumerated Type</h5>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    38
    <p>enum Day { Sunday, Monday, Tuesday, Wednesday, <br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    39
      Thursday, Friday, Saturday } d;</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    40
    <p>d = 5; /* WARNING */<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    41
      d = Monday; /* OK */<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    42
      d = (Day)3 ; /* OK */<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    43
&bull; An empty return statement in a function that is not declared void. For example, the following code results in a warning:<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    44
      int MyInit(void)<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    45
      {<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    46
      int err = GetMyResources();<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    47
      if (err!=0) return; /* ERROR: Empty return statement */</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    48
    <p> /* ... */<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    49
      This is OK:<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    50
      int MyInit(void)<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    51
      {<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    52
      int err = GetMyResources();<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    53
      if (err!=0) return -1; /* OK */</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    54
    <p> /* ... */</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    55
  </div>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    56
</blockquote>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    57
<p> The Extended Error Checking setting corresponds to the pragma <span class="code">extended_errorcheck</span>, described at <a href="../pragmas/p_extended_errorcheck.htm">extended_errorcheck</a>. To check this setting, use <span class="code">__option (extended_errorcheck)</span>.</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    58
<p> See <a href="../symbols/sym_settings.htm">Checking Option Settings</a> for information on how to use this directive.<br />
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    59
</p>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    60
<div id="footer">Copyright &copy; 2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. <br>License: <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a></div>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    61
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    62
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    63
</body>
2b3996fc09a1 revised x86 compiler dates, graphics, CSS, and release notes
fturovic <frank.turovich@nokia.com>
parents: 0
diff changeset
    64
</html>