Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructors of static class instances are not called #157

Open
zapta opened this issue Aug 6, 2022 · 0 comments
Open

Constructors of static class instances are not called #157

zapta opened this issue Aug 6, 2022 · 0 comments

Comments

@zapta
Copy link

zapta commented Aug 6, 2022

Per the discussion at https://community.platformio.org/t/class-constructor-is-not-called-for-global-instances/29100

The test program

class A {
  public:
    A(int val): val_(val) {}
    int val_;
};

A a1(11);
int b = 123;

void main(void) {
  A a2(22);
  printk("a1.val_=%d, a2.val_=%d, b=%d\n", a1.val_, a2.val_, b);
}

Prints

a1.val_=0, a2.val_=22, b=123

Notice that a1.val=0 which suggests that the constructor of the static instance a1 was not called (but was called correctly for the local a2).

My platformio.io is

[env:nrf52_dk]
platform = nordicnrf52
board = nrf52_dk
framework = zephyr
debug_tool = jlink
monitor_speed = 115200
monitor_port = COM7
debug_build_flags = -O0 -g -ggdb
build_flags =
  -I .pio/build/nrf52_dk/zephyr/include/generated
extra_scripts = extra_script.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant