[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ compiling problems




I did notice at one time that in C++, global variables under cris-gcc on the devboard were not
being initialised.

For example, something like:


-------------- main.cpp -----------------

int globalVar = 10;

int main(int argc, char* argv[])
{
   if (globalVar == 10)
   {  
     //  this would not be reached
   }
}

------------ end main.cpp -------------

However, if we changed it to:

-------------- main.cpp -----------------

int globalVar;

int main(int argc, char* argv[])
{
   globalVar = 10;
   if (globalVar == 10)  //  this succ
   {  
      // this is now reached
   }
}

------------ end main.cpp --------------
I'm not sure if the above will work or not, but the behaviour I noticed was very very similar.
I did my workaround and that fixed it so I forgot about it.

The problem you're experiencing might be similar to this... i.e. classes not being initialised and
so the constructors are not called.  

Any comments ?  anyone noticed these problems with C++ too ?

Matt



Jan-Peter Nilsson <janpeter.nilsson@xxxxxxx.com>
Sent by: owner-dev-etrax@xxxxxxx.com

26/06/01 08:02 PM

       
        To:        "'dev-etrax@xxxxxxx.com>
        cc:        
        Subject:        C++ compiling problems



I have some trouble with C++ compiling with the cris-gcc.

When I use a class as the one include below in this text the instance
MyClassInstance is NOT created when the program is started.
It is possible to create new instances while the program is running but the
static instance is for some reason not created.
The code works perfectly on a linux machine with gcc compiling but not on
etrax with cris-gcc.

Thanks in advance
Jan-Peter Nilsson

-- MyClass.h --

class MyClass {

        public:
        MyClass();
        ~MyClass();
        int MyFunction1();
      int MyFunction2();

        protected:
        int myVariable1;
      int myVariable2;
}

-- End MyClass.h --


-- MyClass.cpp --

#include "MyClass.h"

MyClass::MyClass() {
       myVariable1 = 3;
       myVariable2 = 7;
}

MyClass::~MyClass() {
}

int
MyClass::MyFunction1() {
       return myVariable1;
}

int
MyClass::MyFunction2() {
       return myVariable2;
}

MyClass MyClassInstance;

-- End MyClass.cpp --