Date: Fri, 1 Jan 2038 05:24:36 GMT From: rotel@indigo.ie To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: misc/6310: explicit cast needed in floatpoint.h for C++ Message-ID: <203801010524.FAA05229@indigo.ie>
next in thread | raw e-mail | index | archive | help
>Number: 6310
>Category: misc
>Synopsis: explicit cast needed in floatpoint.h for C++
>Confidential: yes
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Apr 15 09:10:02 PDT 1998
>Last-Modified:
>Originator: Niall Smart
>Organization:
>Release: FreeBSD 2.2.6-STABLE i386
>Environment:
>Description:
C++ does not allow implicit conversion from integer types to enum
types. Although this behaviour usually "just" elicits a warning
from the compiler, it may in the future it cause compilation errors.
/usr/include/machine/floatingpoint.h defines the macro's fpgetround()
et al as calls to either __fpgetreg or __fpsetreg. (which are defined
as inline functions if __GNUC__ is defined, there does not seem to
be any replacement for these functions when not using the GNU C
compiler) Both of these functions return an int.
The supplied patch adds appropriate casts before the calls to
__fpgetreg and __fpgetreg.
Also, is anyone in a position to do something about the XXX at the
top of this header file?
/*-
* XXX the following undocumented pollution is exported:
* fpsetsticky().
* FP*FLD, FP*OFF and FP*REG from <machine/ieeefp.h>
*/
>How-To-Repeat:
Compile this code with c++ -Wall:
#include <floatingpoint.h>
int main()
{
fp_rnd_t r;
fp_prec_t p;
fp_except_t e;
r = fpgetround();
r = fpsetround(r);
p = fpgetprec();
p = fpsetprec(p);
e = fpgetmask();
e = fpsetmask(e);
e = fpgetsticky();
e = fpresetsticky(e);
}
>Fix:
*** /usr/include/floatingpoint.h Tue Oct 21 15:14:26 1997
--- floatingpoint.h Fri Jan 1 05:22:59 2038
***************
*** 108,121 ****
/*
* SysV/386 FP control interface
*/
! #define fpgetround() ((__fpgetreg(FP_RND_REG) & FP_RND_FLD) >> FP_RND_OFF)
! #define fpsetround(m) __fpsetreg((m), FP_RND_REG, FP_RND_FLD, FP_RND_OFF)
! #define fpgetprec() ((__fpgetreg(FP_PRC_REG) & FP_PRC_FLD) >> FP_PRC_OFF)
! #define fpsetprec(m) __fpsetreg((m), FP_PRC_REG, FP_PRC_FLD, FP_PRC_OFF)
! #define fpgetmask() ((~__fpgetreg(FP_MSKS_REG) & FP_MSKS_FLD) >> FP_MSKS_OFF)
! #define fpsetmask(m) __fpsetreg(~(m), FP_MSKS_REG, FP_MSKS_FLD, FP_MSKS_OFF)
! #define fpgetsticky() ((__fpgetreg(FP_STKY_REG) & FP_STKY_FLD) >> FP_STKY_OFF)
! #define fpresetsticky(m) __fpsetreg(0, FP_STKY_REG, (m), FP_STKY_OFF)
#define fpsetsticky(m) fpresetsticky(m)
#endif /* !_FLOATINGPOINT_H_ */
--- 108,121 ----
/*
* SysV/386 FP control interface
*/
! #define fpgetround() ((fp_rnd_t) ((__fpgetreg(FP_RND_REG) & FP_RND_FLD) >> FP_RND_OFF))
! #define fpsetround(m) ((fp_rnd_t) __fpsetreg((m), FP_RND_REG, FP_RND_FLD, FP_RND_OFF))
! #define fpgetprec() ((fp_prec_t) ((__fpgetreg(FP_PRC_REG) & FP_PRC_FLD) >> FP_PRC_OFF))
! #define fpsetprec(m) ((fp_prec_t) __fpsetreg((m), FP_PRC_REG, FP_PRC_FLD, FP_PRC_OFF))
! #define fpgetmask() ((fp_except_t) ((~__fpgetreg(FP_MSKS_REG) & FP_MSKS_FLD) >> FP_MSKS_OFF))
! #define fpsetmask(m) ((fp_except_t) (__fpsetreg(~(m), FP_MSKS_REG, FP_MSKS_FLD, FP_MSKS_OFF)))
! #define fpgetsticky() ((fp_except_t) ((__fpgetreg(FP_STKY_REG) & FP_STKY_FLD) >> FP_STKY_OFF))
! #define fpresetsticky(m) ((fp_except_t) __fpsetreg(0, FP_STKY_REG, (m), FP_STKY_OFF))
#define fpsetsticky(m) fpresetsticky(m)
#endif /* !_FLOATINGPOINT_H_ */
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?203801010524.FAA05229>
