Sign in to follow this  

compiler settings in DevC++

This topic is 4277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Some time back I came across someone saying to add this line in DEV C++ -Wall -pedantic -ansi Actually I don't remember where I found this but I had it in my PC saved in doc file. So while cleaning my system, I came across it which made me start this thread. What does these 3 switches basically mean and where should I add them in DEV C++ IDE.

Share this post


Link to post
Share on other sites
A google search for "wall pedantic ansi C++) (that's an 'i' as in 'eye', not 'l' as in 'ell' by the way, I have bad eyesight, haha) returned this link as the 4th result:

http://www.luv.asn.au/overheads/prog/c.html

In the link is this sentence:
Quote:
-Wall turns on all warnings, -pedantic activates a 'pedantic' level of warnings, -ansi turns on checks for conformance with the ANSI C standard


It also says how to do this using the gcc compiler using the command line in linux. I'm not sure how to change the settings in DevC++ to allow this, but there's probably a setting that may say something about command line arguments.

LATER: doing a search for "wall pedantic ansi dev c++" returned this link as the 1st result:

http://www.gidforums.com/t-8002.html

which tells you EXACTLY how to do it in Dev C++, including a .gif of the settings window.

Share this post


Link to post
Share on other sites
-Wall sets the warning level to maximum (-W is for controlling the warning level, and "all" is, of course, "all warnings"). This will cause the compiler to check absolutely everything it can and warn about anything that might potentially be unsafe or unreliable code. It is in general a good practice to write code that compiles with no warnings. Be careful, though - many libraries (sometimes including standard libraries) will generate warnings with this option turned on.

-ansi will turn off special features that the compiler supports that are not standard. This is mostly useful if you are writing code that needs to be compatible with other compilers. One thing to be careful of is that it enables something called trigraphs, where groups of three characters in your string constants may be interpreted in unexpected ways.

-pedantic makes the compiler very strict in what it will accept. In general, it adds some additional warnings, and will refuse to compile programs that violate certain parts of the standard.


DevC++ uses the MinGW compiler, which is basically the GCC compiler. You can find a good page describing all of the GCC compiler options here (the fact that it's a Mac site is totally irrelevant, since GCC is cross-platform). To set these up in DevC++, go to Tools and select Compiler Options.

Share this post


Link to post
Share on other sites
Thank You

I tried writing a sample code by changing the settings


#include<cstdio>
#include<cstdlib>
using namespace std;
unsigned hash ( char key[] )
{
return key[0] - '0';
}
int main()
{

int a[5]={1,2,3,4,5};
printf("%d",a[hash ( "4" )]);
system("pause");
return 0;
}



These were the errors and the warnings. Can you plz help me out in rectifying these
Quote:

cstdio: No such file or directory.

cstdlib: No such file or directory.

3 syntax error before "namespace"

3 [Warning] type defaults to `int' in declaration of `std'

3 ISO C forbids data definition with no type or storage class

In function `main':

[Warning] implicit declaration of function `printf'

13 [Warning] implicit declaration of function `system'

Share this post


Link to post
Share on other sites
oops..I was using .c as file extension but by changing it to .cpp it works fine.

But i don't get it...why can't I use these new ANSI headers in my c file??

Share this post


Link to post
Share on other sites
C and C++ are totally different languages. They also have different standard libraries.

In C, the header files are called stdio.h and stdlib.h. Since C++ is designed to be compatible with C, most C++ compilers will let you include these directly. However, if you use the C headers, the C library functions (such as printf) will get added to the global namespace automatically, which causes namespace pollution. The C++ headers are basically identical except they place the C library functions inside the std:: namespace, along with all the other C++ standard library stuff.


Here's some more reading on the subject:
C++ FAQ Lite: Should I use using namespace std in my code?
C++ FAQ Lite: Why should I use iostream instead of cstdio?

Share this post


Link to post
Share on other sites

This topic is 4277 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this