Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] Re: Problems with constructor of static member class

2005-06-28 by Jaromir

Hi

First :
instead static member , better is use singleton that call function with static object of your class.
Second:
standard startup.s file ( example from freertos or ... ) is only for C, so you nedd add extra code to call all constructors for global (static) obiects. Check WinARM site for example.

Jaromir 
  ----- Original Message ----- 
  From: soren_t_hansen 
  To: lpc2000@yahoogroups.com 
  Sent: Tuesday, June 28, 2005 1:27 PM
  Subject: [lpc2000] Re: Problems with constructor of static member class



  > This is done by redeclaring the _static_ varialbe using the scope 
  > resolution operator to identify the class to which it belongs.
  > This causes storage for the varialbe to be allocated.

  I belive I already do this? In the 2 lines just below (Source)?

  > Try not to use statics within classes - generally
  > also - if this program probably would work - it's not really good code.

  I know that the style isn't great, but it is the best way to approach
  the problem we have at hand :o)

  /Søren

  > > Hi all.
  > > 
  > > I suspect the GNUARM compiler to have a flaw, since the following code
  > > doesn't work as intended:
  > > 
  > > (Header)
  > > class A
  > > {
  > >     public:
  > >         A(int x);
  > >         int m_x;
  > >         static A* get_a_Instance();
  > > 
  > >     private:
  > >         static A m_a;
  > >         static A m_b;
  > > 
  > > };
  > > (Source)
  > > A A::m_a(1);
  > > A A::m_b(2);
  > > 
  > > A::A(int x)
  > > {
  > >     m_x = x;
  > > }
  > > 
  > > A* A::get_a_Instance()
  > > {
  > >    return &m_a;
  > > }
  > > 
  > > int main()
  > > {
  > >    A* temp_a = get_a_Instance();
  > >    int x = temp_a->m_x;
  > > }
  > > 
  > > The problem is that the constuctor doesn_t get called, causing m_x to
  > > have a garbage value (or 0). Even if I make an object of type A first,
  > > it doesn't work. 
  > > Is it something I have to setup in my startup.s file?
  > > 
  > > Best Regards
  > > Søren
  > > 
  > > 
  > > 
  > > 
  > > 
  > > 
  > > Yahoo! Groups Links
  > > 
  > > 
  > > 
  > > 
  > > 
  > > 
  > > 
  > 
  > 
  > [Non-text portions of this message have been removed]




------------------------------------------------------------------------------
  YAHOO! GROUPS LINKS 

    a..  Visit your group "lpc2000" on the web.
      
    b..  To unsubscribe from this group, send an email to:
     lpc2000-unsubscribe@yahoogroups.com
      
    c..  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


------------------------------------------------------------------------------


_________________________________________________________________
List sprawdzony skanerem poczty mks_vir ( http://www.mks.com.pl )


[Non-text portions of this message have been removed]

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.