Announcements
IMPORTANT: Cypress Developer Community is transitioning on October 20th. To learn more and be prepared for this change, check out our latest announcement.
cancel
Showing results for 
Search instead for 
Did you mean: 

WICED Studio Bluetooth

Anonymous
Not applicable

Hello,

I've been dealing with this strange problem since starting out on the CYW20719: declaring a global variable of class type leaves it uninitialized and unusable.

if I have this code for example in main.cpp:

class A {

public:

     A(int val) : a(val) { WICED_BT_TRACE("A()"); }

     int a;

}

A a = A(5);

APPLICATION_START() {

     WICED_BT_TRACE("%d\n", a.a);

}

   

The constructor of A never actually gets called. How can I fix this?

Thank you,

Nicholas

0 Likes
1 Solution
GyanC_36
Employee

Hi Nicholas,

     Currently the WICED SDK does not fully support C++ and also we do not have any plan to support C++ in near future.

-Gyan

View solution in original post

0 Likes
4 Replies
GyanC_36
Employee

Hello Nicholas,

   Could you please share your complete project files and steps to reproduce the issue which will help us to resolve the problem quickly ?

-Gyan

0 Likes
Anonymous
Not applicable

Hello Gyan,

I cannot share my complete project, but I will upload a minimum example today.

Nicholas

0 Likes
Anonymous
Not applicable

Hello gyan,

Here is a small example of my problem:

main.cpp:

extern "C" {

#include "sparcommon.h"

#include "wiced_bt_trace.h"

}

// Needed to have a base class?

void operator delete(void* ptr, unsigned int n) {}

class Base {

public:

     virtual ~Base() {};

     virtual void test() {

          WICED_BT_TRACE("Hello");

     }

};

class A : public Base {

public:

     A(int* b) : b(b) {

          WICED_BT_TRACE("A(%d)\r\n", *b);

     }

     void do_a() {

          WICED_BT_TRACE("Doing %d\r\n", *b);

     }

     virtual void test() {

          Base::test();

          WICED_BT_TRACE(", world!\r\n");

     }

private:

     int* b;

};

// a1's ctor is never, called, and so using it will result in crashes

int bVal = 6;  // primitives are initilized normally

A a1 = A(&bVal);

void test_a(A* a) {

     WICED_BT_TRACE("Trying A*: ");

     a->do_a();

}

void test_base(Base* base) {

     WICED_BT_TRACE("Trying Base*: ");

     base->test();

}

APPLICATION_START()

{

     wiced_set_debug_uart( WICED_ROUTE_DEBUG_TO_PUART );

     WICED_BT_TRACE("---------- Starting App ----------\r\n");

     a1 = A(&bVal);  // Assigning to the global will "kind of" initialize it, but passing pointers to the object fails

     //A a2 = A(&bVal);  // using a2 instead will make everything work

     test_a(&a1);

     test_base(&a1);

     WICED_BT_TRACE("---------- finished ----------\r\n");

}

makefile.mk:

APP_SRC += main.cpp

C_FLAGS += -DWICED_BT_TRACE_ENABLE

Let me know if any other files/info is needed.

Thank you,

Nicholas

0 Likes
GyanC_36
Employee

Hi Nicholas,

     Currently the WICED SDK does not fully support C++ and also we do not have any plan to support C++ in near future.

-Gyan

View solution in original post

0 Likes