[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Unwarranted old-style cast warning and non-critical error
From: |
John W. Eaton |
Subject: |
Unwarranted old-style cast warning and non-critical error |
Date: |
Wed, 22 Aug 2012 16:37:35 -0400 |
On 17-Aug-2012, Daniel J Sebald wrote:
| When building Octave, gcc issues this old-style cast warning:
|
| In file included from builtins.cc:9:0:
| ../../octave/src/interpfcn/variables.h:105:40: warning: use of old-style
| cast
| ../../octave/src/interpfcn/variables.h:105:65: warning: use of old-style
| cast
|
| It is due to the following line of code, and in particular the DBL_MIN
| and DBL_MAX:
|
| extern OCTINTERP_API octave_value
| set_internal_variable (double& var, const octave_value_list& args,
| int nargout, const char *nm,
| double minval = DBL_MIN, double maxval = DBL_MAX);
|
| I think this may be a gcc compiler oversight. I read somewhere that the
| warning went away with gcc version 4.5.0-5, but I have version 4.5.1
| (from late 2010) and I'm still getting the warning.
|
| I tried to get rid of the warning with "static_cast<double>(DBL_MIN)"
| but that did not help.
|
| Can someone please confirm this warning disappeared somewhere along the
| way in the last year and a half?
|
| ...
|
| This leads to a question. Is the line above intended instead to be the
| following (i.e., replace DBL_MIN with -DBL_MAX)?
|
| extern OCTINTERP_API octave_value
| set_internal_variable (double& var, const octave_value_list& args,
| int nargout, const char *nm,
| double minval = -DBL_MAX, double maxval = DBL_MAX);
|
| I'm assuming that the default definitions are meant to be that there is
| no restriction on the value, as with the integer case defined before the
| double case:
|
| extern OCTINTERP_API octave_value
| set_internal_variable (int& var, const octave_value_list& args,
| int nargout, const char *nm,
| int minval = INT_MIN, int maxval = INT_MAX);
|
| However, INT_MIN and DBL_MIN are not analogous. DBL_MIN is the smallest
| positive double value (i.e., greater than zero). I printed out the value:
|
| DBL_MIN = 2.22507e-308
|
| If the minval is meant to be -DBL_MAX, apparently this doesn't make a
| difference in behavior, otherwise a bug would have shown up long ago.
Right. I went with -octave_Inf and octave_Inf instead.
I also checked in another change that replaces all uses of DBL_MIN,
DBL_MAX, DBL_EPSILON, FLT_MIN, FLT_MAX, and FLT_EPSILON in C++ code
with std::numeric_limits functions.
jwe
- Unwarranted old-style cast warning and non-critical error, Daniel J Sebald, 2012/08/17
- Unwarranted old-style cast warning and non-critical error,
John W. Eaton <=
- Re: Unwarranted old-style cast warning and non-critical error, Daniel J Sebald, 2012/08/23
- Re: Unwarranted old-style cast warning and non-critical error, John W. Eaton, 2012/08/23
- Re: Unwarranted old-style cast warning and non-critical error, Daniel J Sebald, 2012/08/23
- Re: Unwarranted old-style cast warning and non-critical error, John W. Eaton, 2012/08/23
- Re: Unwarranted old-style cast warning and non-critical error, John W. Eaton, 2012/08/23
- Re: Unwarranted old-style cast warning and non-critical error, Daniel J Sebald, 2012/08/23
- Re: Unwarranted old-style cast warning and non-critical error, Daniel J Sebald, 2012/08/24