Amiga!
Home
Support
Get the SDK
(Answer) (Category) Amiga Inc. Faq-O-Matic : (Category) Amiga SDK FAQ :
Is there a bug in GCC and thus VPCC regarding class initialization?
The following code will not run under the SDK.  It crashes with the following error:

[shell: child terminated due to signal 7: SIGSEGV: Invalid memory access]

Here is the code taken from 'Learn C++ in 21 Days'.

//Listing 6.4

#include iostream.h

class Cat {
  public:
    Cat(int initialAge);
    ~Cat();
    int GetAge();
    void SetAge(int age);
    void Meow();
  private:
    int itsAge;
};


Cat::Cat(int initialAge)

{

itsAge = initialAge;

}


Cat::~Cat()

{
}


int Cat::GetAge()

{

return(itsAge);

}


void Cat::SetAge(int age)

{

itsAge = age;

}


void Cat::Meow()

{

cout << "Meow.\n";

}


int main()

{

Cat Frisky(5);

Frisky.Meow();

cout << "Frisky is a cat who is " << Frisky.GetAge() << " years old.\n";

Frisky.Meow();

Frisky.SetAge(7);

cout << "Now Frisky is " << Frisky.GetAge() << " years old.\n";

return(0);

}

The line from main() 'Cat Frisky(5);' is where the problem lies.  It seems the initialization of 5 is never executed, or the whole constructor is never called.
I compiled the same program using g++, I get almost the same result in that the code will run, however the first use of the GetAge() method returns a huge number, decidely NOT 5.

I also compiled the code under SAS/C++ and Codewarrior for Windows.  Both worked as expected.
As there seems to be no one from Amiga giving answers to all the questions in this faq, i tell You what I found out: Did You try the Compiler Option -fno-exceptions ? This did help in my case! As mentioned in the manuals, the C++ Exceptions still have bugs! And these bugs seem to be of bigger nature...
[Append to This Answer]
address-suppressed, address-suppressed
Previous: (Answer) How can I change the size of the intent_media-window ?
This document is: http://www.amiga.com/cgi-bin/fom.cgi?file=105
[Search] [Appearance]
This is a Faq-O-Matic 2.710.
This FAQ administered by ray@amiga.com


© 1996-2000 Amiga, Inc.