User Tools

Site Tools


guides:software:gcc:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
guides:software:gcc:start [2020/07/19 14:35] – [Producing Additional Warnings] wikiadminguides:software:gcc:start [2022/08/02 11:59] (current) – external edit 127.0.0.1
Line 160: Line 160:
 ==== Some Useful Arguments ==== ==== Some Useful Arguments ====
  
-  * //--version// will display the version of g++ you are using.+  * //- -version// will display the version of g++ you are using.
     * <code>     * <code>
 $ g++ --version $ g++ --version
Line 218: Line 218:
 Compilers are also capable of analyzing source code to predict where this code may cause run time errors.    By turning on these warnings you are more likely to write code that conforms to the standard and less likely to have common runtime errors in  your code. Compilers are also capable of analyzing source code to predict where this code may cause run time errors.    By turning on these warnings you are more likely to write code that conforms to the standard and less likely to have common runtime errors in  your code.
  
-Your instructor may require one or more of the following flags when compiling code+Your instructor may require one or more of the following flags when compiling code:
  
   * //-Wpedantic//   * //-Wpedantic//
Line 238: Line 238:
   * //-Wconversion//    * //-Wconversion// 
     * Warn when an implicit conversion may change a value.     * Warn when an implicit conversion may change a value.
 +
 +Note:  There are **many** other warning producing flags.
  
 For the following code: For the following code:
Line 246: Line 248:
  
 int main() { int main() {
 +    int a,b;
 +    int c;
  
-    int a; +    if (a = b
-    int b; +       cout << " a is 4" << endl;
- +
-    if (a = 4+
-       cout << " a is 4";+
        a = 5;        a = 5;
  
Line 264: Line 265:
 bad.cpp: In function 'int main()': bad.cpp: In function 'int main()':
 bad.cpp:10:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses] bad.cpp:10:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
-   10 |     if (a = 4)+   10 |     if (a = b)
       |         ~~^~~       |         ~~^~~
 bad.cpp:10:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation] bad.cpp:10:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
-   10 |     if (a == 4)+   10 |     if (a = b)
       |     ^~       |     ^~
 bad.cpp:12:8: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if' bad.cpp:12:8: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
Line 275: Line 276:
    14 |     return 3.14;    14 |     return 3.14;
       |            ^~~~       |            ^~~~
-bad.cpp:8:9: warning: unused variable 'b' [-Wunused-variable] +bad.cpp:8:9: warning: unused variable 'c' [-Wunused-variable] 
-    8 |     int b;+    8 |     int c;
       |         ^       |         ^
-bad.cpp:10:5: warning: 'a' is used uninitialized in this function [-Wuninitialized] +bad.cpp:10:11: warning: 'b' is used uninitialized in this function [-Wuninitialized] 
-   10 |     if (a == 4+   10 |     if (a = b
-      |     ^~+      |         ~~^~~
 </code> </code>
  
guides/software/gcc/start.1595169324.txt.gz · Last modified: 2022/08/02 11:59 (external edit)