wiki:COP3402Spring2011/CompilerSettings

Version 1 (modified by admin, 13 years ago) (diff)

First version copied from Remo's Wiki

Required Compiler Settings for all submitted Programs

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.

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. 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.

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.

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.

Visual Studio

  • Right-click on your project and select "Properties"
  • Select "All Configurations" in the "Configuration:" combo box
  • 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".

  • 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.

Eclipse

  • Right-click on your project in the workspace and select "Properties"
  • Then select "C/C++ Build" --> "Settings"
  • Make sure to select "[ All configurations ]" in the "Configuration:" combo box
  • Then under "Tool Settings -> GCC C Compiler -> Warnings" put a check mark on "Pedantic warnings as errors (-pedantic-errors)"

  • Under "Tool Settings -> GCC C Compiler -> Miscellaneous" make a mark on "Support ANSI programs (-ansi)"

CodeBlocks

  • This assumes that you are using the GNU GCC compiler under CodeBlocks (it supports a bunch of other ones)
  • Once your project is created, right-click on the project in your workspace and select "Build options". A new dialog will open
  • Make sure to select your project name in the left pane (NOT Debug or Release)
  • 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

Attachments (5)

Download all attachments as: .zip