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

ccode flag generates invalid C (references) #48

Closed
DatanoiseTV opened this issue May 11, 2022 · 1 comment
Closed

ccode flag generates invalid C (references) #48

DatanoiseTV opened this issue May 11, 2022 · 1 comment

Comments

@DatanoiseTV
Copy link

At this point, the vultc generates a mix of C and C++. C doesn't support references, therefore on my platform (RP2040) the compiler complains:

n file included from /home/syso/dev/pico-project-generator/i2s-codec-demo/i2s-codec-demo.c:11:
/home/syso/dev/pico-project-generator/i2s-codec-demo/vult.h:16:59: error: expected ';', ',' or ')' before '&' token
   16 | static_inline void Util__ctx_type_0_init(Util__ctx_type_0 &_output_){
      |                                                           ^
/home/syso/dev/pico-project-generator/i2s-codec-demo/vult.h:23:52: error: expected ';', ',' or ')' before '&' token
   23 | static_inline void Util_edge_init(Util__ctx_type_0 &_output_){
      |                                                    ^
/home/syso/dev/pico-project-generator/i2s-codec-demo/vult.h:28:50: error: expected ';', ',' or ')' before '&' token
   28 | static_inline uint8_t Util_edge(Util__ctx_type_0 &_ctx, uint8_t x){
      |                                                  ^
...

@DatanoiseTV DatanoiseTV changed the title -ccode flag generates invalid C (references) ccode flag generates invalid C (references) May 11, 2022
@modlfo
Copy link
Collaborator

modlfo commented May 12, 2022

The code generated by the compiler is C++. If you want to call if from C it is necessary to make wrappers for the C++ functions. Take a look at https://isocpp.org/wiki/faq/mixing-c-and-cpp#call-cpp

Basically, you need to create an extern "C" function that takes a pointer and calls the corresponding C++ function passing the reference.

I dropped the support for pure C code because it is easier to generate C++.

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

2 participants