4 Replies Latest reply on Dec 23, 2018 9:36 PM by GyanC_36

    CYW20719: Global variables not initialized

      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

        • 1. Re: CYW20719: Global variables not initialized
          GyanC_36

          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

          • 2. Re: CYW20719: Global variables not initialized

            Hello Gyan,

             

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

             

            Nicholas

            • 3. Re: CYW20719: Global variables not initialized

              Hello GyanC_36,

               

              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

              • 4. Re: CYW20719: Global variables not initialized
                GyanC_36

                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