Skip to content
New issue

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

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

Already on GitHub? # to your account

Initializing pointer parameters in C++ #419

Closed
cmnrd opened this issue Jul 21, 2021 · 0 comments · Fixed by #1441
Closed

Initializing pointer parameters in C++ #419

cmnrd opened this issue Jul 21, 2021 · 0 comments · Fixed by #1441
Assignees
Labels
cpp Related to C++ target

Comments

@cmnrd
Copy link
Collaborator

cmnrd commented Jul 21, 2021

A drawback of #399 is that the initialization of parameters which have a pointer type does not work anymore. For instance

target Cpp;

reactor Foo(ptr: int*({=nullptr=})) {
    reaction (startup) {=
            std::cout << "Got " << *ptr << "\n";
    =}
}

main reactor {
    private preamble {=
        int bar{42};
    =}
    // don't do this at home
    foo = new Foo(ptr={=&bar=});
}

does not compile.

While generally speaking pointers should be avoided, sometimes they are needed and there is no way around it. So we should support the above program and have it compile correctly. However, this does not seem to be easy to solve because of C++'s peculiarities.

For now, this simple workaround can be used:

target Cpp;

reactor Foo(ptr: int_ptr({=nullptr=})) {
    public preamble {=
        using int_ptr = int*;
    =}
    reaction (startup) {=
        std::cout << "Got " << *ptr << "\n";
    =}
}

main reactor {
    private preamble {=
        int bar{42};
    =}
    // don't do this at home
    foo = new Foo(ptr={=&bar=});
}
@cmnrd cmnrd added the cpp Related to C++ target label Jul 21, 2021
@cmnrd cmnrd added this to the 0.1.0 RC1 milestone Jul 21, 2021
@cmnrd cmnrd self-assigned this Jul 21, 2021
Rodario added a commit that referenced this issue Nov 10, 2021
adds parantheses around the parameters in the code generator
@cmnrd cmnrd removed this from the 0.1.0 milestone Feb 16, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
cpp Related to C++ target
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants