Topic: Conversions of bool to Numeric Types (was: operator if ???)
Author: phalpern@truffle.ma.ultranet.com (Pablo Halpern)
Date: 1996/09/30 Raw View
dhansen@btree.com (Dave Hansen) wrote:
> If you have a bunch of these in
>existing code, it's tedious but not unreasonable (IMHO :) to fix any
>such assignment by inserting the apporpriate cast.
What about library code? A third-party library may very well use int for
bool because bool was not available. Third-party libraries are difficult
to patch because patches will have to re-applied every time a newer
version of the library becomes available. Also, the library might be on
CD-ROM. Even forgetting about 3rd party libraries, modifying a million
lines of code before a new compiler can be installed can sap a project
of more than one day of productivity. In the real-world of business, it
is, IMHO NOT reasable to force casts to be introduced into
previously-working code.
-------------------------------------------------------------
Pablo Halpern phalpern@truffle.ultranet.com
I am self-employed. Therefore, my opinions *do* represent
those of my employer.
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: dhansen@btree.com (Dave Hansen)
Date: 1996/09/19 Raw View
On 19 Sep 1996 10:32:55 PDT, Andrew Koenig wrote in comp.std.c++:
>An example of what breaks:
> int flag;
> flag = x > y;
>If the language is changed so that x > y is bool, rather than int,
>then it had better be possible to convert bool to int.
What I had suggested was that such conversions no longer be implicit.
The conversion would still be possible, but you must make the
conversion explicit in the source. If you have a bunch of these in
existing code, it's tedious but not unreasonable (IMHO :) to fix any
such assignment by inserting the apporpriate cast.
Is this the issue? That is, would a change of this sort be rejected
because it would require existing code to be modified in such a benign
way?
In the example above, what are you really trying to say? IMHO, given
only this snippet, I would say flag should be a bool rather than an
int. This more closely reflects the semantics of the variable. I see
how flag is set. How is it used?
Best Regards.
-=Dave
dhansen@btree.com
I can barely speak for myself, so I certainly can't speak for B-Tree
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: zalman@netcom.com (Zalman Stern)
Date: 1996/09/20 Raw View
Dave Hansen (dhansen@btree.com) wrote:
[Looking for an example where boolean types are used as ints.]
int count_inversions(int sample[], size_t count) {
int inversions = 0;
for (int index = 1; index < count; index++)
inversions += sample[index - 1] > sample[index];
return inversions;
}
Getting rid of the implicit conversion would break a fair bit of code and
while it might not be too painful to fix on an individual basis, its a lot
of pain when totaled up.
-Z-
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: ark@research.att.com (Andrew Koenig)
Date: 1996/09/20 Raw View
In article <199609192019.PAA05859@T-Rex.Minn.Net> dhansen@btree.com writes:
> > int flag;
> > flag = x > y;
> >If the language is changed so that x > y is bool, rather than int,
> >then it had better be possible to convert bool to int.
> What I had suggested was that such conversions no longer be implicit.
> The conversion would still be possible, but you must make the
> conversion explicit in the source. If you have a bunch of these in
> existing code, it's tedious but not unreasonable (IMHO :) to fix any
> such assignment by inserting the apporpriate cast.
> Is this the issue? That is, would a change of this sort be rejected
> because it would require existing code to be modified in such a benign
> way?
Exactly. The committee was given the option to allow the conversion or
not, and voted to allow it (by roughly a 2-1 margin, if I remember right).
--
--Andrew Koenig
ark@research.att.com
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]