Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Liu Hao
On 2017/4/7 8:11, Norbert Pfeiler wrote:
> Wasn’t LH_Mouse’s point that even if the warning is explicitly turned on it
> wouldn’t be shown to the user?
>
> The situation for unions is different in C and C++: (I don’t think that
> it’s just about constness changes anything)
> http://stackoverflow.com/questions/11373203
Nice link. Nevertheless, I don't think most people care about UB unless 
UB bites them (that is, unless UB refuses to work silently). XD

-- 
Best regards,
LH_Mouse


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] Problem using gcc in MSYS2 shell

2017-04-06 Thread Liu Hao
On 2017/4/7 0:56, Edward Diener wrote:
> When trying to compile a project in MSYS2 using mingw-64/gcc I get this
> error:
> (... abridgement ...)
This was an oversight. I replied with detailed information on msys2-users.

-- 
Best regards,
LH_Mouse


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Norbert Pfeiler
Wasn’t LH_Mouse’s point that even if the warning is explicitly turned on it
wouldn’t be shown to the user?

The situation for unions is different in C and C++: (I don’t think that
it’s just about constness changes anything)
http://stackoverflow.com/questions/11373203

Best, Norbert.

Kai Tietz  schrieb am Do., 6. Apr. 2017 um
15:15 Uhr:

> 2017-04-06 15:06 GMT+02:00 Liu Hao :
> > On 2017/4/6 20:47, Kai Tietz wrote:
> >> True.  The reason why we prefer such patter is that it works in both
> >> languages as desired.  Otherwise we would be in need to write
> >> different variants for the languages C/C++.  This looks backward, and
> >> it still doesn't make sure that there might be warnings emitted for C,
> >> or C++ doing const casts.
> > The warning about casting away const-ness can be enabled on GCC6 using
> > `-Wcast-qual` (I am not sure about other versions). But as long as the
> > header file is in a system directory GCC is smart enough to not warn
> > about it even if our user enable that warning, unless `-Wsystem-headers`
> > is also given.
> >
> > --
> > Best regards,
> > LH_Mouse
>
> True, that there are flags to turn such warnings off.  Each compiler
> has its own variants for this.  But well, why we should rely on such
> things.  As you already mentioned, are our headers system ones, and
> therefore as silent as possible.  Nothing is worse in experience to
> users, if they suddenly see warnings, they don't want to see.  And
> that all because they enabled some warning flags for "their" code.
>
> Cheers,
> Kai
>
>
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
2017-04-06 15:06 GMT+02:00 Liu Hao :
> On 2017/4/6 20:47, Kai Tietz wrote:
>> True.  The reason why we prefer such patter is that it works in both
>> languages as desired.  Otherwise we would be in need to write
>> different variants for the languages C/C++.  This looks backward, and
>> it still doesn't make sure that there might be warnings emitted for C,
>> or C++ doing const casts.
> The warning about casting away const-ness can be enabled on GCC6 using
> `-Wcast-qual` (I am not sure about other versions). But as long as the
> header file is in a system directory GCC is smart enough to not warn
> about it even if our user enable that warning, unless `-Wsystem-headers`
> is also given.
>
> --
> Best regards,
> LH_Mouse

True, that there are flags to turn such warnings off.  Each compiler
has its own variants for this.  But well, why we should rely on such
things.  As you already mentioned, are our headers system ones, and
therefore as silent as possible.  Nothing is worse in experience to
users, if they suddenly see warnings, they don't want to see.  And
that all because they enabled some warning flags for "their" code.

Cheers,
Kai

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
2017-04-06 14:47 GMT+02:00 Kai Tietz :
> 2017-04-06 13:38 GMT+02:00 Norbert Pfeiler
> :
>> I’m pretty sure that cast via union is UB in C++ whereas C-style casting
>> away constness isn’t (only writing to the resulting object would be) but it
>> may result in compilers issuing warnings about style (because C++ has
>> const_cast).

Hmm, undefined behavior???  no, this is pretty well defined behavior.
In C++ world a union cast is pretty much the same as a
reinterpret_cast (or a C style cast without conversion operator).  And
a const_cast is just a smaller set out of the realm of
reinterpret_cast.

Cheers,
Kai

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Liu Hao
On 2017/4/6 20:47, Kai Tietz wrote:
> True.  The reason why we prefer such patter is that it works in both
> languages as desired.  Otherwise we would be in need to write
> different variants for the languages C/C++.  This looks backward, and
> it still doesn't make sure that there might be warnings emitted for C,
> or C++ doing const casts.
The warning about casting away const-ness can be enabled on GCC6 using 
`-Wcast-qual` (I am not sure about other versions). But as long as the 
header file is in a system directory GCC is smart enough to not warn 
about it even if our user enable that warning, unless `-Wsystem-headers` 
is also given.

-- 
Best regards,
LH_Mouse


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
2017-04-06 13:38 GMT+02:00 Norbert Pfeiler
:
> I’m pretty sure that cast via union is UB in C++ whereas C-style casting
> away constness isn’t (only writing to the resulting object would be) but it
> may result in compilers issuing warnings about style (because C++ has
> const_cast).
>
> Best, Norbert.

True.  The reason why we prefer such patter is that it works in both
languages as desired.  Otherwise we would be in need to write
different variants for the languages C/C++.  This looks backward, and
it still doesn't make sure that there might be warnings emitted for C,
or C++ doing const casts.

Cheers,
Kai


> Kai Tietz  schrieb am Do., 6. Apr. 2017 um
> 11:50 Uhr:
>
>> A cast via union looks like this:
>> type1 *foo(const type1 *my_const_ptr)
>> {
>> union {
>>   type1 *t1;
>>   const type1 *ct1;
>> } v;
>> v.ct1 = my_const_ptr;
>> return v.t1;
>> }
>>
>> The advantage of such a pattern is that no type conversion
>> errors/warnings are shown.  So for casting from const to none-const,
>> this variant is to be preferred.  (and it works for C, and C++!!!)
>>
>> Cheers,
>> Kai
>>
>> 2017-04-05 15:51 GMT+02:00 Mateusz Mikuła :
>> >> Hmm, using here "wchar_t *" as cast looks wrong.  Actually we should
>> >> use anyway PUWSTR_C instead.
>> > I noticed it a bit too late and sent another patch casting to PUWSTR_C.
>> >> Nevertheless we can have here a const/none-const conversion (means
>> >> const specifiers for C-runtime function isn't regarded right?).  I
>> >> would suggest to introduce a union-cast instead to avoid further
>> >> warnings instead.
>> > Conversion from const pointer to normal pointer is definitely unsafe but
>> > that's probably what GCC just did.
>> > I'm unsure what you mean by "union-cast" but you can commit your fix.
>> >
>> >
>> >
>> --
>> > Check out the vibrant tech community on one of the world's most
>> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> > ___
>> > Mingw-w64-public mailing list
>> > Mingw-w64-public@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>> >
>>
>>
>> --
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> ___
>> Mingw-w64-public mailing list
>> Mingw-w64-public@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>>
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Norbert Pfeiler
I’m pretty sure that cast via union is UB in C++ whereas C-style casting
away constness isn’t (only writing to the resulting object would be) but it
may result in compilers issuing warnings about style (because C++ has
const_cast).

Best, Norbert.

Kai Tietz  schrieb am Do., 6. Apr. 2017 um
11:50 Uhr:

> A cast via union looks like this:
> type1 *foo(const type1 *my_const_ptr)
> {
> union {
>   type1 *t1;
>   const type1 *ct1;
> } v;
> v.ct1 = my_const_ptr;
> return v.t1;
> }
>
> The advantage of such a pattern is that no type conversion
> errors/warnings are shown.  So for casting from const to none-const,
> this variant is to be preferred.  (and it works for C, and C++!!!)
>
> Cheers,
> Kai
>
> 2017-04-05 15:51 GMT+02:00 Mateusz Mikuła :
> >> Hmm, using here "wchar_t *" as cast looks wrong.  Actually we should
> >> use anyway PUWSTR_C instead.
> > I noticed it a bit too late and sent another patch casting to PUWSTR_C.
> >> Nevertheless we can have here a const/none-const conversion (means
> >> const specifiers for C-runtime function isn't regarded right?).  I
> >> would suggest to introduce a union-cast instead to avoid further
> >> warnings instead.
> > Conversion from const pointer to normal pointer is definitely unsafe but
> > that's probably what GCC just did.
> > I'm unsure what you mean by "union-cast" but you can commit your fix.
> >
> >
> >
> --
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > ___
> > Mingw-w64-public mailing list
> > Mingw-w64-public@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
> >
>
>
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public


Re: [Mingw-w64-public] [PATCH] stralign: cast ua_wcschr and ua_wcsrchr returns to wchar_t *

2017-04-06 Thread Kai Tietz
A cast via union looks like this:
type1 *foo(const type1 *my_const_ptr)
{
union {
  type1 *t1;
  const type1 *ct1;
} v;
v.ct1 = my_const_ptr;
return v.t1;
}

The advantage of such a pattern is that no type conversion
errors/warnings are shown.  So for casting from const to none-const,
this variant is to be preferred.  (and it works for C, and C++!!!)

Cheers,
Kai

2017-04-05 15:51 GMT+02:00 Mateusz Mikuła :
>> Hmm, using here "wchar_t *" as cast looks wrong.  Actually we should
>> use anyway PUWSTR_C instead.
> I noticed it a bit too late and sent another patch casting to PUWSTR_C.
>> Nevertheless we can have here a const/none-const conversion (means
>> const specifiers for C-runtime function isn't regarded right?).  I
>> would suggest to introduce a union-cast instead to avoid further
>> warnings instead.
> Conversion from const pointer to normal pointer is definitely unsafe but
> that's probably what GCC just did.
> I'm unsure what you mean by "union-cast" but you can commit your fix.
>
>
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Mingw-w64-public mailing list
> Mingw-w64-public@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mingw-w64-public
>

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public