Topic: ANSI draft: integral conversion problem
Author: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Date: 1995/05/12 Raw View
In article <3otggj$b4n@nntp5.u.washington.edu>
ghogenso@u.washington.edu (Gordon Hogenson) writes:
|> This question relates to overload resolution of functions
|> that take "long int" as an argument.
|> The problem is that the conversion "int --> long int" is
|> classified by the draft as a "conversion" rather than a
|> "promotion" (if I understand 4.5, conv.prom and 4.7,
|> conv.integral) correctly. The result of this is that
|> int --> long int
|> is "just as good" a conversion as
|> int --> double
|> which is problematic in many common cases.
Correct. But the rules are complicated enough as it is.
A good general design rule: if you have an overload for any of the
integral types, overload on int, too.
Consider:
|> int pow(long int, long int);
|> double pow(double, long int);
|> double pow(double, double);
I would add:
inline int
pow( int i , int j )
{
return pow( (long)i , (long)j ) ;
}
Simple. No run-time overhead. And it ensures that things like
`pow( 2 , 10 )' get the function you want.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Author: ghogenso@u.washington.edu (Gordon Hogenson)
Date: 1995/05/11 Raw View
This question relates to overload resolution of functions
that take "long int" as an argument.
The problem is that the conversion "int --> long int" is
classified by the draft as a "conversion" rather than a
"promotion" (if I understand 4.5, conv.prom and 4.7,
conv.integral) correctly. The result of this is that
int --> long int
is "just as good" a conversion as
int --> double
which is problematic in many common cases. Consider:
int pow(long int, long int);
double pow(double, long int);
double pow(double, double);
the call:
int i;
double x;
pow(x, i);
is ambiguous. If int-->long int were counted as an integral
promotion, then the call would resolve, which I believe is
the sensible result here.
Any comments? Is this something that was thought about or is it
an oversight?
--
--
Gordon J. Hogenson <ghogenso@u.washington.edu> Tel. (206) 685-2951