What the...!? Weird BCC/Dinkumware error

I'm still messing with locales and facets.

Can someone explain this one to me?

The following code does not work with Borland C++ 5.82:
1
2
3
4
5
6
7
8
9
10
11
12
13
...
#include "utf8_locale.hpp"

const std::locale utf8_locale(        // A global object 
  std::locale::classic(),
  new duthomhas::unicode::utf8_facet
  );

int main()
  {
  wofstream outf;
  outf.imbue( utf8_locale );
  ...

But the following does:
1
2
3
4
5
6
7
8
9
10
11
12
13
...
#include "utf8_locale.hpp"

int main()
  {
  const std::locale utf8_locale(       // A local object 
    std::locale::classic(),
    new duthomhas::unicode::utf8_facet
    );

  wofstream outf;
  outf.imbue( utf8_locale );
  ...

Is there some sort of magic trick to locales that I am missing? Why won't it work for a global locale but only a local locale?

(It worked perfectly both ways using the MinGW GCC.) It also took me forever to figure out that this was what I had done differently from the (very simple) example I was working off of.

Thank you for your time.
Perhaps some sort of problem resolving dependencies between static objects?
My best guess is that the Borland compiler hasn't initialized the classic locale before main() is called...
Topic archived. No new replies allowed.