I am facing a very odd behaviour of the Embarcadero C++ Builder when using the CLANG compiler.
The example is very simple:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
std::wostringstream woss;
woss << std::wstring(L"N°1: ") << (int) 1234;
woss << '\r' << '\n';
woss << std::wstring(L"N°2: ") << (float) 12.34;
Memo1->Lines->Add( woss.str().c_str() );
std::ostringstream oss;
oss << std::string("N°3: ") << (int) 4567;
oss << '\r' << '\n';
oss << std::string("N°4: ") << (float) 45.67;
Memo1->Lines->Add( oss.str().c_str() );
}
As long as the code is compiled with Borlands classic compiler, it prints exactly what I am expecting:
- N°1: 1234
- N°2: 12.34
- N°3: 4567
- N°4: 45.67
However, as soon as I switch to the CLANG compiler (bcc32c) (by unchecking "use classic compiler" in the settings dialog) I get the following result:
- N°1: 1234
- N°2: -0
- N°3: 4567
- N°4: -0
Edit: please ignore the issue with the std::string - the important thing is the false floating point number.
(Not only that the float numbers get crushed, there seems also to be an issue with the interpretation of regular std::string's.)
What is the problem with bcc32c and how can I handle this?
I am using Embarcadero C++ Builder 10.0 (Seattle) for the WIN32 target platform.
thank you
float
s but it would explain theN°3
. – Scheff Dec 1 '20 at 10:49oss << '\r' << '\n';
useoss << '\n';
only. The\n
will automatically be converted to the correct new line character for each platform by the C runtime. And try to use UTF-8 encoding only for new compilers. Probably Embarcadero is so old that it uses "ANSI" code pages – phuclv Dec 1 '20 at 10:59N°3
in detail:°
has the code 176 ('\xb0'
) in Windows-1252 but is a two byte sequence in UTF-8:"\xc2\xb0"
. Now, these two bytes in Windows-1252 again:°
. So, I assume your string literal in source code is encoded in UTF-8 but the output is done decoding it as Windows-1252. – Scheff Dec 1 '20 at 11:03N�1: 1234 N�2: 12.34 N°3: 4567 N°4: 45.67
with G++ in Windows. (Although without that ancient__fastcall
thingy, but this shouldn't change anything) – nada Dec 1 '20 at 11:07