The Standard C++ and Boost Libraries
Developer Guide

Developer Guide

Table of Contents

Known Issues
Use of Global Destructor
Issues with new Operator
The id Member Issue
Interleaving Symbian and Standard C++ Code

 


Known Issues

 


Use of Global Destructor

Symbian does not invoke destructors of global objects upon program termination. For example, in the code below, the destructor ~foo() is not called upon program termination. At the moment, it is advised not to perform any important operations using destructors.

#include 
using namespace std; 
class foo
{
public:
foo()
{
cout <<"Entering foo\n"; 
}
~foo()
{
cout <<"Leaving foo\n";
}
};
foo foo_bar; 
int main(void)
{
return 0;
}

 


Issues with new Operator

Throwing bad_alloc or any object from new on ARMV5 platfrom crashes. RVCT reports an exception when new throws bad_alloc. The problem occurs even if the user throws any object from within an overloaded operator new. The following new signatures are affected:

void *operator new(unsigned int aSize);
void *operator new[](unsigned int aSize);

The following code snippet is an example that depicts the problem:

class Dummy
{
}; 
void *operator new(unsigned int aSize)
{
void* __y = malloc(aSize);
// try to simulate bad alloc
if (__y == 0)
{
throw Dummy(); //this will result in a crash
}
return __y;
}

To implement user owned overloaded version of new, the user must implement them as class specific. The other way this could be achieved is by defining new similar to:

void* operator new(size_t s,newarg) throw (std::bad_alloc) 

and invoking it as:

Myclass* my = new(S60) Myclass()

 


The id Member Issue

The id member variable of facet classes cannot be accessed directly, it has to be accessed via the GetFacetLocaleId() interface.

Following code snippet is an example that illustrates how to uselocale::id while writing an application on top of the Standard Template Library (STL). Declare a static method GetFacetLocaleId() instead of the member variable id when, defining a class base_facet inherited from locale::facet in a header file.

//b_facet.h 
class base_facet : public locale::facet 
{ 
public: 
static locale::id; 
GetFacetLocaleId(); // in place of static locale::id
id; 
};
In the source file define the method GetFacetLocaleId().
//b_facet.cpp
locale::id base_facet_id; 
locale::id& base_facet::GetFacetLocaleId()
{ 
return base_facet_id; 
}

 


Interleaving Symbian and Standard C++ Code

The user must exercise caution while using try or catch, and trap while interleaving Symbian C++ and Standard C++ code. Adapter code is required to handover or suppress exception coming from the Standard C++ to Symbian C++ code.

Following code snippet illustrates how to use the adaptor code. Adaptor code can be a part of DLLA.

DLL A - Symbian C++ code

void CDoIt::Doit()
{
   class foo *p = new __foo__();
   p->bar();
   delete p;
};

DLLB - Standard C++ code

class foo {
public:
  foo(); //constructor
  bar(); // throw exception
};

DLLC - Adaptor code

class __foo__ {
  foo *p;
public:
  __foo__();
  bar();
};

void __foo__::__foo__()
{
   int err = 0;
   try {
      p = new foo();
   } catch {
     err = some error
   }
   User::LeaveIfError(err);
};
void __foo__::bar()
{
   int err = 0;
   try {
      p->bar();
   } catch {
     err = some error
   }
   User::LeaveIfError(err);
};

Give feedback on this article


ŠNokia 2008

Back to top


This material, including documentation and any related computer programs, is protected by copyright controlled by Nokia. All rights are reserved. Copying, including reproducing, storing, adapting or translating, any or all of this material requires the prior written consent of Nokia. This material also contains confidential information, which may not be disclosed to others without the prior written consent of Nokia.

Nokia is a registered trademark of Nokia Corporation. S60 and logo is a trademark of Nokia Corporation. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. Other company and product names mentioned herein may be trademarks or tradenames of their respective owners.