Mail Archives: djgpp/1998/11/29/09:56:02
From: | ranla AT post DOT tau DOT ac DOT il (Tal Lavi)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Works on WATCOM, doesn't work on DJGPP?
|
Date: | Fri, 27 Nov 1998 15:39:52 LOCAL
|
Organization: | Tel-Aviv University Computation Center
|
Lines: | 59
|
Message-ID: | <ranla.126.000B98BD@post.tau.ac.il>
|
NNTP-Posting-Host: | slip-304.tau.ac.il
|
X-Newsreader: | Trumpet for Windows [Version 1.0 Rev B final beta #4]
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hello,
I'm using DJGPP 2.81, under DOS.
I wanted to overload the = operator for my fixed point class, as seen in
another class I download somewhere, that was meant for compiling under WATCOM.
inline fixed &operator= (int a) {value = long(a)<<16;return *this;}
As copied for the class's documentation:
"In general, there are four of 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.
Does this is a true DJGPP flaw?
Is there a way(that will work under DJGPP, ofcourse) to overload
the =,+,-,*,/ operators so that every combination of fixed point, ordinal
types, floats and doubles can be used?(also: int=Fixed, float=Fixed)
Below is a minimal class and test program(in one file), that contains this problem.
#include <stdio.h>
#include <conio.h>
class Fixed
{
public:
signed long data;
Fixed(void){}
Fixed(int x){data=(signed long)(x)<<16;}
Fixed(float x){data=(signed long)(x*65536.0+0.5);}
Fixed(double x){data=(signed long)(x*65536.0+0.5);}
Fixed &operator=(Fixed const &x){data=x.data; return *this;}
Fixed &operator=(int x) {data=(signed long)(x)<<16; return *this;}
Fixed &operator=(float x) {data=(signed long)(x*65536.0+0.5);return *this;}
Fixed &operator=(double x){data=(signed long)(x*65536.0+0.5);return *this;}
};
int main()
{
Fixed a;
int b=1;
signed long c=2;
a=b;//compiles OK
a=c;//compile errors
return(0);
}
Thanks in advance,
Tal Lavi ranla AT post DOT tau DOT ac DOT il
- Raw text -