[AD] C++ fix math (proposal from Gillius)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Sorry - I didn't realise this didn't make it to the list. I'm still 
getting used to KMail's list handling...

Bye for now,
- -- 
Laurence Withers,  lwithers@xxxxxxxxxx
(GnuPG 04A646EA) http://www.lwithers.demon.co.uk/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9VmdNUdhclgSmRuoRAsizAKCH3XfyJgSz7GmHDxFuiOgRzOnl9wCdFYxj
S4tUE60bDjZPw5O7aDhWvQU=
=kGrp
-----END PGP SIGNATURE-----
--- Begin Message ---
On 10 Aug 2002 at 17:50, Laurence Withers wrote:
> class fix {
>   public:
>     // ...
>     void radtofix() throw() { v = radtofix(v); }
>     void fixtorad() throw() { v = fixtorad(v); }
> };

I used to use no-throw exception specifiers, but check this out:

http://www.boost.org/more/lib_guide.htm#Exception-specification

The bad thing about C++ is even if you declare "throw()" it doesn't mean a 
function throws nothing.  Any C++ code can throw any exception at any time. 
 The thing that the "throw()" does is run the bad exception type handler if 
you throw something, or if you throw a non-specified exception.  This is 
the reason why some compilers have to implicitly place try/catch blocks in 
your code, and entering these blocks affects performance.  Therefore with 
the combonation that the exception specifier really means nothing and helps 
no one and gives no guarantees and decreases performance, I think I may 
agree with Boost's rationale.

While not particularly asking for a change, there is an alternate API 
choice we can consider:

class fix {
public:
  // ...
  fix radtofix() const { return fix(radtofix(v)); }
  fix fixtorad() const { return fix(fixtorad(v)); }
  static fix radtofix( float x ) { return fix(radtofix(ftofix(x))); }
};

This has the benefit of allowing rad/fix conversions for const fix objects. 
 The static function is not really related, but might be another useful 
addition.

Gillius


--- End Message ---


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/