On Tue, Feb 17, 2004 at 12:23:37PM -0500, Mike M wrote:

> The discussion of declaring main is  off the point though.  The example
> is to show that the C++ compilers weren't complaining about the .h on the
> #includes.

Off the point, but still important: portable C++ requires that main()
returns an int.

> It's puzzling to me why it was necessary to make iostream when 
> iostream.h works just fine.  (That's a retorical question aimed at
> the C++ godz).

Part of the formal C++ standard includes the specification of the C++
Standard Library. That spec says what the names of the standard header
files should be, and the spec says that none of the standard header
files have an extension.

Vendors can do whatever they want behind the scenes to implement the
spec. In the case of GNU C++, they choose to implement it by putting an
"iostream" file in the standard include search path, and that file
#include's an "iostream.h". In theory, a vendor could choose to
implement "#include <iostream>" by loading a pre-compiled header file
from a database, and not providing an actual file called iostream at
all. The only important thing is that the vendor supports #include
<iostream> correctly.

If you want to write portable C++, you must also use the proper header
name. That means

 #include <iostream>

NOT
 
 #include <iostream.h>

The latter might work for GNU C++, but it might not work for somebody
else's C++. To reiterate: when you #include <iostream.h>, you are
emphatically NOT getting definitions for the C++ Standard Library's
iostream classes. You might think you are, but you're not, and your code
won't be portable.

The main reason why this became the standard is because they needed to
provide backwards compatibility. Vendors had already been shipping
iostream.h, but the Standard put iostream into the std namespace, and
many vendors' iostream.h did not. So, they needed to come up with new
headers that could follow the Standard without breaking backwards
compatibility with existing code that #include's iostream.h.

The standards committee decided that the most straightforward approach
would be to eliminate the extension altogether.

Not also that if you want to include C headers (e.g., stdlib.h), the
correct include is

 #include <cstdlib>

NOT

 #include <stdlib.h>

-- 
Dave Carrigan
Seattle, WA, USA
[EMAIL PROTECTED] | http://www.rudedog.org/ | ICQ:161669680
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-C++-DNS-PalmOS-PostgreSQL-MySQL

Attachment: signature.asc
Description: Digital signature

Reply via email to