C++ class variables are not initialized

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

C++ class variables are not initialized

Jump to solution
1,052 Views
__invited__hari
Contributor V

Hi,

I am facing weird problem with C++.

With the below example, the print message supposed to be 'Value=22'. But I am seeing it as 'Value=1".

May I know the reason for it please?

FYI, I am using S32DS for ARM C++ Application.

Thanks,

Hari

#include "S32K148.h" /* include peripheral declarations S32K148 */
#include <stdio.h>

class MyClass
{
public:
   int a=10;
   MyClass()
   {
      a += 11;
   }
};

MyClass myClass;

void func1(void)
{
   int x = ++myClass.a;
   printf("Value=%d",x);
}

int main()
{
   func1();

   while(1);
   return 0;
}

0 Kudos
1 Solution
795 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

it looks like that there is bug in startup file - thanks for report. You can fix it by adding 

bl _start 

instead

bl main 

in the startupS32K148.S file:

pastedImage_1.png

Hope it helps. 

Jiri 

View solution in original post

2 Replies
795 Views
__invited__hari
Contributor V

Thank you Jiri.

That works. Appreciated your quick turnaround.

Best,

Hari

0 Kudos
796 Views
jiri_kral
NXP Employee
NXP Employee

Hi, 

it looks like that there is bug in startup file - thanks for report. You can fix it by adding 

bl _start 

instead

bl main 

in the startupS32K148.S file:

pastedImage_1.png

Hope it helps. 

Jiri