| 1 | = Required Compiler Settings for all submitted Programs = |
| 2 | [[PageOutline]] |
| 3 | We received some feedback from students on their returned assignment 1a grade concerning the fact that their code compiled and ran fine in Eclipse or CodeBlocks, but we sometimes couldn't compile it in Visual Studio. That's a valid complaint and based on the fact that the compilers treat certain features of C / C++ differently. |
| 4 | |
| 5 | Here is the gist of it. There are three different standards for C (C90, C95, and C99) and three different standards for C++ (C++98, C++03, and C++05TR1). Now the problem is that Visual Studio supports the newest C++05TR1 standard, but only C95 as C standard, while gcc (used in CodeBlocks and Eclipse by default) supports most features of C99 and all features of C++05TR1. |
| 6 | So it could happen that code compiles with gcc using C99 features, but will produce a bunch of errors in Visual Studio, because these features are not implemented there. |
| 7 | |
| 8 | Because we still want to give students a choice to use their preferred compiler / IDE, so we have to find some common denominator. In the interest of everybody, Dr. Hughes decided to only support the ANSI standards C90 and C++98 for your assignment submissions. |
| 9 | |
| 10 | On this page, I will give you some instructions on how to change the required settings for the most commonly used IDEs: Visual Studio, Eclipse, and CodeBlocks. If you happen to use a different compiler, you have to find out for yourself on how to adjust the parameters accordingly. |
| 11 | |
| 12 | == Visual Studio == |
| 13 | - Right-click on your project and select "Properties" |
| 14 | - Select "All Configurations" in the "Configuration:" combo box |
| 15 | - Then in the left property pane click through to "Configuration Properties -> C/C++ -> Language". On the right side make sure that "Disable Language Extensions" is set to "Yes". |
| 16 | |
| 17 | [[Image(visual_studio_disable_extensions.png)]] |
| 18 | |
| 19 | - Without closing the window, select "Configuration Properties -> C/C++ -> Advanced" in the left pane. There will be a setting "Compile As" on the right side that determines if Visual Studio interprets your code as C or C++ code. Please make sure to select the appropriate option for your project. |
| 20 | |
| 21 | [[Image(visual_studio_compile_as.png)]] |
| 22 | |
| 23 | == Eclipse == |
| 24 | - Right-click on your project in the workspace and select "Properties" |
| 25 | - Then select "C/C++ Build" --> "Settings" |
| 26 | - Make sure to select "[ All configurations ]" in the "Configuration:" combo box |
| 27 | - Then under "Tool Settings -> GCC C Compiler -> Warnings" put a check mark on "Pedantic warnings as errors (-pedantic-errors)" |
| 28 | |
| 29 | [[Image(eclipse_pedantic_errors.png)]] |
| 30 | |
| 31 | - Under "Tool Settings -> GCC C Compiler -> Miscellaneous" make a mark on "Support ANSI programs (-ansi)" |
| 32 | |
| 33 | [[Image(eclipse_ansi.png)]] |
| 34 | |
| 35 | |
| 36 | == CodeBlocks == |
| 37 | - This assumes that you are using the GNU GCC compiler under CodeBlocks (it supports a bunch of other ones) |
| 38 | - Once your project is created, right-click on the project in your workspace and select "Build options". A new dialog will open |
| 39 | - Make sure to select your project name in the left pane (NOT Debug or Release) |
| 40 | - Then under "Compiler settings" and "Compiler Flags" make sure to put a check mark on the "In C mode, support all ISO C90 programs. In C++ mode, remove GNU extensions that conflict with ISO C++ [-ansi]" and the "Treat as errors the warnings demanded by strict ISO C and ISO C++" options |
| 41 | |
| 42 | [[Image(codeblocks_gnu_gcc_settings.png)]] |