Am 03.11.2013 20:33, schrieb Tommi Mäkitalo:
Am 03.11.2013 18:33, schrieb Dmitry Dneprov:
...
Traditionally in C and C++ conversion between int and char types
was always implicit. So as your new type is used in standard
routines, I suggest support this semantic,
i.e. make this constuctor implicit.
Regards,
Dmitry
I think you are right.
There are currently 4 constructors for cxxtools::Char with one parameter:
Char(char ch);
Char(unsigned char ch);
Char(wchar_t ch);
explicit Char(value_type ch); // value_type beeing int32_t
This is a source of ambiguity. I think the best way is to replace all
with a single constructor:
Char(value_type ch);
Then there is no ambiguity and C++ converts all int and char types
implicitly. Since the value type is int32_t, it gives the compiler
even the chance to warn, if one uses a 64 bit type to initialize a
Char, which may loose bits. And the user should check, if it is really
what he wants.
Tommi
Hi,
I just tried it out. Cxxtools can be compiled with that single
constructor. And Char is used quite often in cxxtools, so it is a hint,
that it would be ok.
Two unittests fail, but it is easy to fix. The ISO-8859-1 and
ISO-8859-15 decoders fail since it converts a char to cxxtools::Char
implicitly. But when char is negative, the sign bit is expanded to the
higher bytes of cxxtools::Char, which results in a wrong code. The char
value e.g. 0xa4 should result in 0x000000a4 but since (char)0xa4 is
negative, it results in 0xffffffa4. I need to add a explicit cast to
unsigned char to get the right result.
Tommi
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general