Topic: Difference in C++ Standard Library


Author: girish.shetty@nokia.com ("Girish Shetty")
Date: Tue, 14 Jun 2005 14:03:04 GMT
Raw View
Hi All,

I have got two different implementation of C++ Standard Library, and there
are lots of difference between them !!

I have downloaded these two:

gcc-4.0.0.tar.gz

libstdc++-2.8.1.1.tar.gz

For example, In case of gcc-4.0.0.tar.gz,

ifstream is defined as :

typedef basic_fstream<char> fstream; ///< @isiosfwd

And the only two constructers provided by the basic_fstream class are:

basic_fstream()

basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in |
ios_base::out)

Again, APIs (with parameter) differ in this case..

Where in case of libstdc++-2.8.1.1.tar.gz, its defined like this:

class fstream : public fstreambase, public iostream {

public:

fstream() : fstreambase() { }

fstream(int fd) : fstreambase(fd) { }

fstream(const char *name, int mode, int prot=0664)

: fstreambase(name, mode, prot) { }

fstream(int fd, char *p, int l) : fstreambase(fd, p, l) { } /*Deprecated*/

void open(const char *name, int mode, int prot=0664)

{ fstreambase::open(name, mode, prot); }

};

Which matches with Windows C++ Standard Library.

Now the confusuon is, which one is as per the standard ?

Regards

Girish



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: "P.J. Plauger" <pjp@dinkumware.com>
Date: Tue, 14 Jun 2005 09:58:46 CST
Raw View
""Girish Shetty"" <girish.shetty@nokia.com> wrote in message
news:Rnure.2104$_k2.36918@news2.nokia.com...

> I have got two different implementation of C++ Standard Library, and there
> are lots of difference between them !!

Not unusual.

> I have downloaded these two:
>
> gcc-4.0.0.tar.gz
>
> libstdc++-2.8.1.1.tar.gz
>
> For example, In case of gcc-4.0.0.tar.gz,
>
> ifstream is defined as :
>
> typedef basic_fstream<char> fstream; ///< @isiosfwd
>
> And the only two constructers provided by the basic_fstream class are:
>
> basic_fstream()
>
> basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in |
> ios_base::out)

These are the two constructors required by the C++ Standard.

> Again, APIs (with parameter) differ in this case..
>
> Where in case of libstdc++-2.8.1.1.tar.gz, its defined like this:
>
> class fstream : public fstreambase, public iostream {

Ah, now this is a problem. The C++ Standard requires that
fstream be a typedef for template class basic_fstream<char>
(as above). You're looking at either a very old library or
the "traditional" iostreams sometimes shipped with a
standard-conforming library.

> Which matches with Windows C++ Standard Library.

The first one. Some releases of VC++ also include the old
headers with names like iostream.h (note the .h on the end)
which implement the traditional library. But you should
avoid using these headers in modern code, and *never*
mix old and new.

> Now the confusuon is, which one is as per the standard ?

The first one.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: caj@cs.york.ac.uk (chris jefferson)
Date: Tue, 14 Jun 2005 15:04:33 GMT
Raw View
Girish Shetty wrote:
> Hi All,
>
> I have got two different implementation of C++ Standard Library, and there
> are lots of difference between them !!
>
> I have downloaded these two:
>
> gcc-4.0.0.tar.gz
>
> libstdc++-2.8.1.1.tar.gz
>

 From the libstdc++ homepage

What... is your name?

The GNU Standard C++ Library v3, or libstdc++-v3. Older snapshots of
this library were given the name libstdc++-2.9x up until the release of
GCC 3. This is a complete rewrite from the previous libstdc++-v2.

gcc-4.0.0 (and all versions of gcc 3) come with a copy of libstdc++-v3.
libstdc++-v2 is unmaintained and shouldn't be used unless you have a
very good reason for it. Any differences you found are almost certainly
signs of old pre-standardisation which were removed when libstdc++-v3
came out.

If you want to compare versions of the standard library, compare
libstdc++-v3 (which came with gcc-4.0.0) with rougewave
(http://www.roguewave.com/opensource/index.cfm) and STLport
(http://www.stlport.org) (as two random examples, I'm not claiming these
are good, or better than other options. They are free however). You
should find much fewer differences.

Chris

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: squell@alumina.nl (Marc Schoolderman)
Date: Tue, 14 Jun 2005 17:34:07 GMT
Raw View
Girish Shetty wrote:

> I have got two different implementation of C++ Standard Library, and there
> are lots of difference between them !!

Yes, I've seen that often, especially in the I/O library. Some
implementations are implemented as per the letter of the standard (e.g.
when to throw badbit/failbit - some implementations never throw without
setting badbit because of some ambiguous wording in the original
standard, if I recall correctly), whereas others implement what the
Standard was actually intending to say.

> ifstream is defined as :

> And the only two constructers provided by the basic_fstream class are:
> basic_fstream()
> basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in |
> ios_base::out)

This is correct.

> Where in case of libstdc++-2.8.1.1.tar.gz, its defined like this:
> class fstream : public fstreambase, public iostream {

This is incorrect. According to the standard, std::fstream must be a
typedef for basic_fstream<char>.

Also, if I'm not mistaken, libstdc++ 2.8.1.1 is a VERY old version of
the GNU libstdc++-v2 series. They've since switched to libstd++-v3 which
is included with every G++ release. I wouldn't be surprised if libstdc++
2.8.1.1 is from a time when there was no (formal) C++ Standard! :)

~Marc.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]