Hirrolot / datatype99

Algebraic data types for C99
MIT License
1.36k stars 23 forks source link

it seems that datatype doesn not compile with c++ #7

Closed picca closed 3 years ago

picca commented 3 years ago

I need to compile some c++ code with some C code.

but it seems that this is not possible.

libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -DPKGDATA=\"/usr/local/share/hkl\" -fpermissive -I.. -I../hkl -I../hkl3d -I../hkl3d/bullet/src -I../third-party/ -ftrack-macro-expansion=0 -I/usr/include/bullet -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -O2 -Wall -MT hkl3d.lo -MD -MP -MF .deps/hkl3d.Tpo -c hkl3d.cpp  -fPIC -DPIC -o .libs/hkl3d.o
In file included from ../hkl/hkl-geometry-private.h:27,
                 from hkl3d.cpp:38:
../hkl/hkl-parameter-private.h: In function ‘HklParameterType Parameter()’:
../hkl/hkl-parameter-private.h:39:1: error: ‘ParameterTag’ was not declared in this scope; did you mean ‘Parameter’?
   39 | datatype(
      | ^~~~~~~~
      | Parameter
../hkl/hkl-parameter-private.h:39:1: error: expected primary-expression before ‘)’ token
../hkl/hkl-parameter-private.h:39:9: error: expected ‘)’ before ‘{’ token
   39 | datatype(
      | ~~~~~~~~^
      |         )
../hkl/hkl-parameter-private.h:39:9: error: expected ‘;’ before ‘)’ token
   39 | datatype(
      | ~~~~~~~~^
      |         ;
../hkl/hkl-parameter-private.h:39:1: error: expected primary-expression before ‘)’ token
   39 | datatype(
      | ^~~~~~~~
../hkl/hkl-parameter-private.h: At global scope:
../hkl/hkl-parameter-private.h:39:1: warning: uninitialized ‘const metalang99_semicolon_39’ [-fpermissive]

do I miss something ?

picca commented 3 years ago

the datatype is this one

datatype99(
        HklParameterType,
        (Parameter)
        );

it expands into this

extern "C" {

typedef struct HklParameterType HklParameterType; typedef struct HklParameterType ParameterSumT; struct HklParameterType { enum { ParameterTag } tag; union { char dummy; } data; }; inline static HklParameterType Parameter(void) { return ((HklParameterType){.tag = ParameterTag, .data.dummy = '\0'}); } static const char metalang99_semicolon_39 __attribute__((unused))

         ;
Hirrolot commented 3 years ago

Try now, it must work on C++11.

picca commented 3 years ago

Thanks a lot, it works now :))