guides:software:gcc:start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| guides:software:gcc:start [2020/07/19 14:25] – [Producing Additional Warnings] wikiadmin | guides: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. |
| * < | * < | ||
| $ 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. | Compilers are also capable of analyzing source code to predict where this code may cause run time errors. | ||
| - | 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: |
| * // | * // | ||
| Line 232: | Line 232: | ||
| * // | * // | ||
| * Warn about uninitialized variables. | * Warn about uninitialized variables. | ||
| + | * This flag requires //-O**n**// for some variables. | ||
| + | * See below. | ||
| * // | * // | ||
| * Warn when shadow variables are declared in a scope | * Warn when shadow variables are declared in a scope | ||
| Line 237: | Line 239: | ||
| * 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: | ||
| + | <code c++> | ||
| + | #include < | ||
| + | |||
| + | using namespace std; | ||
| + | |||
| + | int main() { | ||
| + | int a,b; | ||
| + | int c; | ||
| + | |||
| + | if (a = b) | ||
| + | cout << " a is 4" << endl; | ||
| + | a = 5; | ||
| + | |||
| + | return 3.14; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Compiling without additional flags produces no warnings. | ||
| + | < | ||
| + | $ g++ bad.cpp | ||
| + | $ g++ -g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion bad.cpp | ||
| + | bad.cpp: In function 'int main()': | ||
| + | bad.cpp: | ||
| + | 10 | if (a = b) | ||
| + | | ~~^~~ | ||
| + | bad.cpp: | ||
| + | 10 | if (a = b) | ||
| + | | ^~ | ||
| + | bad.cpp: | ||
| + | 12 | a = 5; | ||
| + | | ^ | ||
| + | bad.cpp: | ||
| + | 14 | | ||
| + | | ^~~~ | ||
| + | bad.cpp: | ||
| + | 8 | int c; | ||
| + | | ^ | ||
| + | bad.cpp: | ||
| + | 10 | if (a = b) | ||
| + | | ~~^~~ | ||
| + | </ | ||
| + | |||
| + | You should use all command line flags specified by your instructor. | ||
| + | |||
| + | |||
| + | Note: If you wish to avoid typing command line arguments, you may wish to investigate | ||
| + | * Makefiles | ||
| + | * Command Line History | ||
| ==== Other Arguments ==== | ==== Other Arguments ==== | ||
guides/software/gcc/start.1595168736.txt.gz · Last modified: 2022/08/02 11:59 (external edit)