vult-dsp / vult

Vult is a transcompiler well suited to write high-performance DSP code
https://vult-dsp.github.io/vult
Other
490 stars 25 forks source link

ccode flag generates invalid C (references) #48

Closed DatanoiseTV closed 1 year ago

DatanoiseTV commented 2 years ago

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){
      |                                                  ^
...
modlfo commented 2 years ago

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++.