Topic: Re: Proposal: Strongly Typed Logica
Author: dsp@bdal.de (=?windows-1252?Q?=22Daniel_Kr=FCgler_=28ne_Spangenberg=29=22?=)
Date: Tue, 5 Apr 2005 02:01:14 GMT Raw View
Hello Richard Kaiser,
Richard Kaiser schrieb:
> Current Boolean operators =93and=94, =93or=94 and =93not=94 (like &&, |=
| and !)=20
> are not type-safe. Since their operands are subject to integral=20
> promotions, expressions like
>
> int i; bool b;
> if (b and i) ...
> if (b or i) ...
> if (not i) ...
>
> are valid, although they may not be intended. Such errors could be=20
> detected by the compiler, if the operands of =93and=94, =93or=94 and =93=
not=94=20
> would be required to be of type bool. Integral promotion for the=20
> operands of the traditional operators &&, || and ! should remain the=20
> same.
>
> Since the alternative tokens =93and=94, =93or=94 and =93not=94 are not =
widely=20
> used, there would be not many conflicts for existing programs. All=20
> these conflicts could be resolved by using the traditional operators=20
> &&, || and !.=20
The reason for providing the alternative representations was an=20
accommodation for systems with limited input capabilities and which=20
don't necessarily support characters (and character input) like &, |=20
and so on. Your proposal would not consider those minorities.
It is true, that these alternative tokens are rarely used, but providing=20
them with a different meaning than their corresponding primary tokens=20
would cause more rules and more trouble, I assume, because
you replace alternatives by actually new operators. Should it be=20
possible to user-define these new operators for user-defined types?
Besides, I have never seen a problem with integral -> bool promotions,=20
although my original background was Pascal and its derivatives. Do you=20
have some Java background?
Greetings from Bremen,
Daniel
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: squell@alumina.nl (Marc Schoolderman)
Date: Tue, 5 Apr 2005 02:03:46 GMT Raw View
Richard Kaiser wrote:
> Current Boolean operators =93and=94, =93or=94 and =93not=94 (like &&, |=
| and !) are=20
> not type-safe. Since their operands are subject to integral promotions,=
=20
> expressions like
>=20
> int i; bool b;
> if (b and i) ...
> if (b or i) ...
> if (not i) ...
>=20
> are valid, although they may not be intended.=20
My understanding of "and", "or" and "not", just like the keywords 'xor',=20
'bitand', 'bitor' and so on was that they are 100% synonyms, and I think=20
everybody expects them to be that. To my eye, immediately, the above=20
code signalled "if(b and i !=3D 0)".
I'm not even sure those keywords were introduced for code readability.
Anyway, making "&&" more expressive and flexible than "and" is a sure=20
way to guarantee nobody will ever used the keyword.
~Marc
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]