2005-10-12 18:55:17     static class initialization

Document created by Aaronwu Employee on Sep 26, 2013
Version 1Show Document
  • View in full screen mode

2005-10-12 18:55:17     static class initialization

John DeHority (UNITED STATES)

Message: 3789    I am trying to port the Rose RealTime C++ runtime libraries to uClinux. I have succeed in getting the plain C version of the runtime library working.

 

The C++ version uses a construct similar to the following:

 

someClass.cc

 

#include <RTsomeClass.h>

#include <RTMutex.h>

 

static RTMutex critical;

 

void RTsomeClass::lock(void)

{

critical.enter();

}

 

void RTsomeClass::unlock(void)

{

critical.leave();

}

 

 

It compiles and links successfully. But at runtime the critical.enter() function causes an error because constructor RTMutex::RTMutex never got called for the static instance named "critical" that is declared in someClass.cc

 

Am I missing a compiler flag to cause initialization of the static classes?

 

I'm suspecting a compiler bug here. The Rose runtime data classes (including the offending RTsomeClass and RTMutex) are compiled into a library. That library is then linked to the "user application", in this case a simple model that prints "Hello World" on stdout.

 

I'm using g++-3.4.4 and the R3 kernel.

This compiles and executes as expected with g++-3.3.4 on Suse9.2. Am I wrong to expect the constuctor for RTMutex to be called when a variable is declared using:

static RTMutex someNewVariableName;

 

Thanks for any insights.

 

John DeHority

QuoteReplyEditDelete

 

 

2005-10-13 07:13:49     RE: static class initialization

Jie Zhang (UNITED STATES)

Message: 3793    It should works. Could you try this simpler test to see what it print out?

 

#include <iostream>

 

class A {

private:

int a;

public:

A () {a = 12345678; std::cout << "Constructor!" << std::endl;}

void test () {std::cout << "a = " << a << std::endl;}

};

 

static A foo;

 

int main ()

{

foo.test ();

return 0;

}

QuoteReplyEditDelete

 

 

2010-07-12 12:08:27     Re: static class initialization

Chris Peters (UNITED STATES)

Message: 91173   

 

I see there is no solution posted here for this problem, but I am having the same problem myself.  Anyone have any ideas?

QuoteReplyEditDelete

 

 

2010-07-13 09:54:12     Re: static class initialization

Steve Kilbane (UNITED KINGDOM)

Message: 91198   

 

John and Chris,

 

Have you tried Jie's simple example to see whether you see the same problem?

 

I've tried compiling Jie's example using a receive trunk build, and it works.

 

skilban@edin-florence:~/tmp> bfin-linux-uclibc-g++ --version

 

bfin-linux-uclibc-g++ (ADI-trunk/svn-4637) 4.3.5

 

 

 

skilban@edin-florence:~/tmp> bfin-uclinux-g++ --version

 

bfin-uclinux-g++ (ADI-trunk/svn-4637) 4.3.5

 

root:/proc> cat version

 

Linux version 2.6.34-ADI-2010R1-pre-svn8863 (skilban@edin-ohio) (gcc version 4.3.5 (ADI-trunk/svn-4622) ) #10 Thu Jun 10 09:21:35 BST 2010

 

steve

Attachments

    Outcomes