Incorrect Code?

Incorrect Code?

Post by Bill Rudol » Sun, 31 Mar 2002 05:44:21



I receive the following error when trying to run the program below using CW 7.0:

Error   : internal compiler error: File: 'CTemplateTools.c' Line: 1477
hello.cpp line 71    DFactory<S,T,BaseDistribution,U,CreateDistribution> df;

Is my code incorrect or is this a compiler error?

Thanks.

Bill

#include <map>

class RandInt32 {
public:
        RandInt32():x(0) {}
        void seed(unsigned long s) {x=s;}
        double obs() {return abs(x*1103515245+12345)/2147483648;}
private:
        long abs(long y) {return y&0x7fffffff;}
        unsigned long x;

Quote:};      

template<class S>
class BaseDistribution {
public:
        virtual S operator()()=0;
        virtual void seed(unsigned long)=0;
        virtual ~BaseDistribution(){}

Quote:};

template<class S,class T>
class Exponential:public BaseDistribution<S> {
public:
        Exponential(const S& m):mean(m),var(std::pow(m,2)),t() {}
        virtual S operator()(){return -mean*std::log(1-t.obs());}
        virtual void seed(unsigned long i) {t.seed(i);}
        virtual ~Exponential() {}
private:
        T t;
        S mean,var;

Quote:};

template<class S,class T>
struct CreateDistribution {
        virtual BaseDistribution<S>* operator()(const S&)=0;
        virtual ~CreateDistribution(){}

Quote:};

template<class S,class T>
struct CreateExponential:public CreateDistribution<S,T> {
        virtual BaseDistribution<S>* operator()(const S& a)
        { return new Exponential<S,T>(a);}
        virtual ~CreateExponential(){}

Quote:};

template<class S,class T,template<class> class AbstractProduct,
        typename IdentifierType,template<class,class> class ProductCreator>
class DFactory {
        typedef std::map<IdentifierType,ProductCreator<S,T>* > AssocMap;
public:
        bool reg(const IdentifierType& id,ProductCreator<S,T>* creator)
        { return assoc.insert(AssocMap::value_type(id,creator)).second;}
        bool unreg(const IdentifierType& id) { return assoc.erase(id)==1;}
        AbstractProduct<S>* createobject(const IdentifierType& id,const S& a) {
                typename AssocMap::iterator pos=assoc.find(id);
                if (pos!=assoc.end()) return (*(pos->second))(a);
                return 0; }
        ~DFactory() {  
                AssocMap::iterator pos=assoc.begin();
                for(;pos!=assoc.end();++pos) { delete (pos->second);} }
private:
        AssocMap assoc;

Quote:};

template<class S,class T,class U>
class IsDistribution {
public:
        IsDistribution():df() { df.reg('E',new CreateExponential<S,T>());}        
private:
        DFactory<S,T,BaseDistribution,U,CreateDistribution> df;

Quote:};

int main( void )
{
        IsDistribution<double,RandInt32,char> r1;
Quote:}

 
 
 

Incorrect Code?

Post by MW Ro » Mon, 01 Apr 2002 00:55:48




Quote:>I receive the following error when trying to run the program below using CW
>7.0:

>Error   : internal compiler error: File: 'CTemplateTools.c' Line: 1477
>hello.cpp line 71    DFactory<S,T,BaseDistribution,U,CreateDistribution> df;

>Is my code incorrect or is this a compiler error?

Both,  we should not have an Internal compiler error, I will submit this
as a bug.

You have errors

You are missing two include files,  cmath and algorithm,

This line here is wrong which causes one other error.

   AssocMap::iterator pos=assoc.begin();

I wasn't sure how this was to be corrected, so I can't say if correcting
this fixes the ICE or not,  I'll report the ICE.

Ron

--
       TOP PICK   HandHeld Computing - issue 4.5
   "The best overall development tool for the Palm OS"

 Metrowerks, maker of CodeWarrior  -  "Software Starts Here"  


 
 
 

1. Compiler generates incorrect code

Comparisons of ULARGE_INTEGER variables seems to give the reverse results.
The following code was printed from debug: -

Break at 406ed1 (_TestProc) ai2rpsut.obj
[ 327] {
[ 328] ULARGE_INTEGER first;
[ 329] ULARGE_INTEGER second;
[ 330]
406ebc pushl %ebp
406ebd movl %esp,%ebp
406ebf subl $0x10,%esp
406ec2 movl $0x4,%ecx
406ec7 decl %ecx
406ec8 movl $0xfffa5a5a,(%esp,%ecx,4)
406ecf jne 406ec7
[ 331] first.LowPart = 0;
406ed1 movl $0x0,-8(%ebp) (first)
[ 332] first.HighPart = 0;
406ed8 movl $0x0,-4(%ebp)
[ 333] second.LowPart = 0;
406edf movl $0x0,-16(%ebp) (second)
[ 334] second.HighPart = 0;
406ee6 movl $0x0,-12(%ebp)
[ 335] if (first.QuadPart > second.QuadPart)
406eed movl -12(%ebp),%edx
406ef0 movl -16(%ebp),%eax (second)
406ef3 leal -8(%ebp),%ecx (first)
406ef6 cmpl %edx,0x4(%ecx)
406ef9 jg 406f01
406efb jl 406f08
406efd cmpl %eax,(%ecx)
406eff jbe 406f08
[ 336] return 1;
406f01 movl $0x1,%eax
406f06 jmp 406f0d
[ 337] return 0;
406f08 movl $0x0,%eax
[ 338] }
406f0d leave
406f0e ret
Break at 406ed1 (_TestProc) ai2rpsut.obj Page 1

If I read the assembly code correctly the compare at 406ef6 is testing the
HighPart of 'second' to the HighPart of 'first' and 406ef9 branches into the
'return 1' statement if second > first.  This is not what the C statement at
[335] says - it should be a branch to the 'return 0' statement at 406f08.

Can anyone confirm this is a compiler bug?

Thanks

Tony Brett

2. Yamaha DB60XG

3. visibroker 3.2 and eventservices, incorrect java-code generated

4. CSB and Ultima6

5. gcc & incorrect exit codes

6. Servers

7. Code code code

8. Meurtre a Venise / Murders in venice

9. P-code, T-code, and Uni-Code Intermediate Languages

10. Vuescan, Nikon Coolscan IV, and incorrect frame offsets with negatives

11. VueScan displays incorrect dpi

12. REPOST: Vuescan Film Types missing or incorrect with v7.3.9 Mac Version

13. Vuescan Film Types missing or incorrect with v7.3.9 Mac Version