[Gdal-dev] Wide-character filenames with GDAL file IO?

Mateusz Loskot mateusz at loskot.net
Wed Sep 20 15:46:19 EDT 2006


Ben Discoe wrote:
> Mateusz,
> 
>> -----
>> From: Mateusz Loskot
>> Sent: Tuesday, September 19, 2006 12:38 PM
>>
>>> The problem i have _not_ solved is what to do on Windows with code 
>>> which uses std::ifstream() instead of fopen().
>> std::ifstream is a type from the C++ library but fopen() is a 
>> function from the C library.
>> I'm not sure I understand what's here to be solved
> 
> What's here to be solved is GDAL's source.  If it only calls fopen(), then
> it can be replaced with the function i described.  If GDAL also uses the C++
> stream classes for file IO (which i hope it does not), then there exists the
> problem i described.

AFAIK, GDAL does not uses C++ SL streams, so C library calls are the
only option. So, I don't see much problems with using them, besides
customizing GDAL itself to work with wide-char strings.

>> Simply, you have to decide if you use streams or file 
>> descriptor, both are different approaches used in different 
>> languages (C/C++) and are based on different libraries (C/C++).
> 
> Obviously.  But like many large projects, GDAL is both C and C++, and uses
> both standard libraries.

Generally yes, but in GDAL C++ library is not widely used, so C
functions can be considered as the only option.

>>> MSDN documents that there is a
>>> (wchar_t*) version of std::ifstream() constructor 
>>> (http://msdn2.microsoft.com/en-us/library/zek0beca.aspx),
>> Simply, there are two specializations of basic_ifstream, one 
>> for char -> ifstream and one for wchar_t -> wifstream.
> 
> There may be, but that's irrelevant.  I said two _constructors_, not two
> template instances.  If that MSDN link works for you, you can see that
> std::ifstream<char> has two constructors, one which takes a char*filename,
> and one which takes a wchar_t*filename.  This is totally independent of the
> base type of the template, which has to do with the data read from the
> stream, not the charset of the filename used to construct it.
>
> As i mentioned, the MSDN documentation has those two constructors, but the
> headers and library that come with MSVC 7.1 do not have both.

Now, everything is clear. We're talking about two different things,
but that's because I've had no idea about this ctor.
And because the problem is in the MSDN documentation :-)
The second constructor you see, that takes const wchar_t* parameter
is a non-standard *extension* introduced by Microsoft.
That's why you can't find it in the MSVC++ 7.1, as well as you won't
find it in libstdc++, Dinkumware C++ and even in Comeau C/C++ - the most
up-to-date C++ compiler.

Standard ctors of basic_ifstream are specified in the
27.8.1.6 basic_ifstream constructors of C++ Language Standard.

Also, in Dinkumware's manual:

http://www.dinkumware.com/manuals/?manual=compleat&page=fstream.html#basic_ifstream

Dinkumware manuals are very good regarding ISO C++ compliance.

I just wonder why Microsoft does not inform that this wide-char-based
ctor is an extension. There is a relevant note about it but only in
the <fstream> file, line 591:

// construct with wide-named file -- EXTENSION


>> AFAIR there is <fstream> header in C++ library provided with 
>> Visual C++ 7.1 compiler.
> 
> Yes, but the constructor does not take a wchar_t*filename.

Because, what I'm expalining above, there is no wide-char based
ctor in basic_ifstream class, according to the C++ standard.

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list