www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/25/10:16:25

Date: Wed, 25 Nov 1998 10:21:07 -0500
Message-Id: <199811251521.KAA26697@envy.delorie.com>
From: DJ Delorie <dj AT delorie DOT com>
To: djgpp AT delorie DOT com
In-reply-to: <ranla.113.000409B4@post.tau.ac.il>
Subject: Re: (Probably not but...) a flaw in DJGPP?
References: <ranla DOT 113 DOT 000409B4 AT post DOT tau DOT ac DOT il>
Reply-To: djgpp AT delorie DOT com

> inline fixed &operator= (int a) {value = long(a)<<16;return *this;}
> 
> As copied for the class's documentation:
> 
> "In general, there are four functions for each operation , one each for 
> fixed,int, float and double. Thankfully, Watcom will automatically cast
> any other ordinal types (short, long, char, unsigned int, etc.) to int."
> 
> I was very disapointed to see that DJGPP does not have that quality!
> A simple test program compiles fine when using ints, but gives me errors for
> unknown combination of operands if I use unsigned longs.

Unsigned longs can't cast to ints, because they may represent values
that aren't representable in an int.  You can cast signed or unsigned
shorts or chars, or signed ints, but not unsigned ints or any longs
(yes, I know sizeof(long) == sizeof(int) in djgpp, but you can't
guarantee that, so you shouldn't do it).

If Watcom is silently truncating your numbers and doing an automatic
conversion that may corrupt your data, it has a bug.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019