Forums | developer.brewmp.com Forums | developer.brewmp.com

Developer

Forums

Can I import my C++ code for my windows mobile platform into the BrewMP while in Visual Studio? If so, how?

You can use c++ with BREWMP, yes. However, the core of BREWMP is C
code, so you should pay attantion to the standard things when mixing C and C++
code. In addition, you will want to overload new and delete (and for [] as well)
so that they use the MALLOC and FREE brew helper functions.

You can use c++ with BREWMP, yes. However, the core of BREWMP is C
code, so you should pay attantion to the standard things when mixing C and C++
code. In addition, you will want to overload new and delete (and for [] as well)
so that they use the MALLOC and FREE brew helper functions.

This is an old question. Here is some other posts about it (among many posts):
http://brewforums.qualcomm.com/archive/index.php/t-830.html
http://brewforums.qualcomm.com/showthread.php?s=&threadid=1502&highlight...
http://brewforums.qualcomm.com/archive/index.php/t-4113.html
Here is my code:
shared.h
#if defined(__cplusplus)
void * operator new(size_t);
void operator delete(void *);
void* operator new[](size_t);
void operator delete[](void *);
extern "C" void __assert(const char *, const char *, int);
#endif
shared.cpp
#if defined(__cplusplus)
void * operator new(size_t sz) { return MALLOC(sz); }
void operator delete(void *p) { FREE(p); }
void* operator new[](size_t sz) { return MALLOC(sz); }
void operator delete[](void *p) { FREE(p); }
extern "C" void __assert(const char * , const char * , int ) {}
#endif
-J_Tom_Moon_79

This is an old question. Here is some other posts about it (among many posts):
http://brewforums.qualcomm.com/archive/index.php/t-830.html
http://brewforums.qualcomm.com/showthread.php?s=&threadid=1502&highlight...
http://brewforums.qualcomm.com/archive/index.php/t-4113.html
Here is my code:
shared.h
#if defined(__cplusplus)
void * operator new(size_t);
void operator delete(void *);
void* operator new[](size_t);
void operator delete[](void *);
extern "C" void __assert(const char *, const char *, int);
#endif
shared.cpp
#if defined(__cplusplus)
void * operator new(size_t sz) { return MALLOC(sz); }
void operator delete(void *p) { FREE(p); }
void* operator new[](size_t sz) { return MALLOC(sz); }
void operator delete[](void *p) { FREE(p); }
extern "C" void __assert(const char * , const char * , int ) {}
#endif
-J_Tom_Moon_79

I would also recommend using the BREW macro FREEIF() instead of FREE() in the overload of the delete operation.  This will protect from errors caused by freeing null pointers, which is allowed in C++ without error.

I would also recommend using the BREW macro FREEIF() instead of FREE() in the overload of the delete operation.  This will protect from errors caused by freeing null pointers, which is allowed in C++ without error.