HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free and registered users see less advertising! If you just want to browse through the existing questions, just select the forum that you want to visit from the selection below. Otherwise, click here to register!. We highly recommend that you print a copy of our Guide for New Members. Enjoy!

warning during compilation of a C program

I compiled a file on a fedora OS using g++ program. Though the file was successfully compiled i see the following warning. Please explain this warning for me. Thank in advance!!

In file included from /usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c ++/4.0.0/backward/iostream.h:31,
from helloworld.cpp:1:
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../../include/c++/4.0.0/backward/back ward_warning.h:32:2: warning: #warning This file includes at least one deprecate d or antiquated header. Please consider using one of the 32 headers found in sec tion 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated h eader <iostream.h>. To disable this warning use -Wno-deprecated.

I'm guessing one of the first things in your program is #include <iostream.h>? You should be using: #include <iostream>, it should compile faster. I think the difference is with the .h it has to compile the header, and with the other one it just links to the library. I could be mistaken though.

63,000 bugs in the code, 63,000 bugs,
ya get 1 whacked with a service pack,
now there&#039;s 63,005 bugs in the code!!

It's the same compilation wise if you use
#include <header.h>
vs
#include <header>
But C++ langauge specific states, that you shuldn't use .h when you include headers provided by the system.

It's actualy very simple, in your system provided iostream.h theres a line ie:

Code:

#include "backward_warning.h"

And this backward_warning header, will detect if the compiler has the __DEPRICATED flag set. If it does, it will display the warning you're seeing.
Basicaly teh file contains:

Code:

#ifdef __DEPRECATED
#warning This file includes at least one deprecated or antiquated header. \
Please consider using one of the 32 headers found in section 17.4.1.2 of the \
C++ standard. Examples include substituting the <X> header for the <X.h> \
header for C++ includes, or <iostream> instead of the deprecated header \
<iostream.h>. To disable this warning use -Wno-deprecated.
#endif

As you might have noticed by now, having a line with #warning in your code, results in the compiler returning that line as a compiler warning.

It's common used, if you have a huge code base, and you're playing around, then while trying some quick-fix hacked together you might add a line like:

Code:

#warning Please reconsidder if this is the correct way to do X

And while you're compiling you're beeing reminded that specific part might need a closer reconsidderation, then when having to weed out all these things in your code, you can search for that specific warning and know you'll be taken to the portion you want to investigate.

It's the same compilation wise if you use
As you might have noticed by now, having a line with #warning in your code, results in the compiler returning that line as a compiler warning.

It's common used, if you have a huge code base, and you're playing around, then while trying some quick-fix hacked together you might add a line like:

Code:

#warning Please reconsidder if this is the correct way to do X

And while you're compiling you're beeing reminded that specific part might need a closer reconsidderation, then when having to weed out all these things in your code, you can search for that specific warning and know you'll be taken to the portion you want to investigate.

Interesting. I found that if I use <header> instead of <header.h> and "using namespace std;" just after I declare headers I do not get the warning anymore

if you're part of a larger group working on the same project, you need to have control of what namespace you're working within, if someone decides to rewrite a std1 namespace which has a mangeling of cout/cin, and you're on some level is including his header defining this mangeling, as well as stating "using namespace std1", then when you state "using namespace std" you can't be sure if it will be the system std or his mangeling you're using.

So for good practice, I like to write specificaly what namspace I'm adressing in my code.