I hope this is the right group to discuss a STLport bug in Borland
C++BuilderX 1.0 (and probably in BCB 6). Shortly speaking, the following
small C++ program simply doesn't work under Win32:
#include <iostream>
using namespace std;
int wmain ()
{
wcout << L"Hello, world!" << endl;
return 0;
}
Nothing is printed on the console. No matter how it's compiled:
bcc32 -tWU -tWC test.cpp (statically linked, single-threaded)
bcc32 -tWR -tWU -tWC test.cpp (dynamically linked, single-threaded)
bcc32 -tWM -tWU -tWC test.cpp (statically linked, multi-threaded)
bcc32 -tWR -tWM -tWU -tWC test.cpp (dynamic. linked, multi-threaded)
Going a bit deeper, I found out that the wide-character stream objects
(wcout, wcin, ...) are not initialized properly. So I took the only
available STLport source (for C++Builder 6, taken from
http://codecentral.borland.com/codecentral/ccweb.exe/listing?id=17579)
and fixed the initialization bug (patch appended).
[For the curious: In _Stl_create_wfilebuf[iostream.cpp:163], the file
stream buffers for the wide character stream objects are created and
opened. They are opened by file handle, but this particular open()
operation, which delegates to _M_open[fstream.cpp:636] always fails
(line 710).]
I could not find out how much the STLport version coming with
C++BuilderX is different from the BCB 6's one; at least the publicly
accessible headers under include/stl/ and include/stlport/ only differ
in three small places. So I _think_ that there are hardly any
differences. (I also think that BCB6 suffers from the same bug; however,
I don't know for sure, because I don't own Borland C++Builder 6. Perhaps
someone can check this?)
If you don't intend to use the standard wide-character streams, you are
probably better off with the original C++BuilderX STLport version. If
you do, I recommend to use the patched BCB6 version.
Best regards,
Christoph Schulz
diff -urN bcb6beta\src\fstream.cpp bcb6beta-r1\src\fstream.cpp
--- bcb6beta\src\fstream.cpp Sat Apr 02 21:50:31 2005
+++ bcb6beta-r1\src\fstream.cpp Sat Apr 02 22:18:13 2005
@@ -58,6 +58,7 @@
# include <fcntl.h> // For _O_RDONLY, etc
# endif
# include <sys/stat.h> // For _fstat
+# include <io.h> // For _get_osfhandle
# elif !defined(__STL_WINCE)
# include <io.h> // For _get_osfhandle
# include <fcntl.h> // For _O_RDONLY, etc
@@ -680,7 +681,7 @@
return false;
}
// # elif defined(_STLP_USE_WIN32_IO) && defined (_MSC_VER) || (defined(__MINGW32__) && defined(__MSVCRT__))
-# elif (defined(__STL_USE_WIN32_IO) && defined (_MSC_VER) && !defined(__STL_WINCE)) || \
+# elif (defined(_STLP_USE_WIN32_IO) && (defined (_MSC_VER) || defined (__BORLANDC__)) && !defined(__STL_WINCE)) || \
(defined(__MINGW32__) && defined(__MSVCRT__))
if (_M_is_open || file_no == -1)
@@ -696,7 +697,11 @@
if (init_mode != ios_base::__default_mode)
_M_openmode = init_mode;
else
+#if ! defined (__BORLANDC__)
_M_openmode = _SgI::_get_osfflags(file_no, oshandle);
+#else
+ return false;
+#endif
# else
(void)init_mode; // dwa 4/27/00 - suppress unused parameter warning