From: Stephen S. <rad...@gm...> - 2013-01-21 23:57:54
|
On Mon, Jan 21, 2013 at 5:41 PM, Jeremia Bär <je...@je...> wrote: > Hi, > > I looked at liblo for the first time today. I had some problems getting > the example codes to run until I realized this is because of a subtle > difference of C and C++. In 'example_server.c', line 82 > > lo_arg_pp(types[i], argv[i]); > > (where types is of 'const char*') compiles nicely as C code using gcc. > Using the same code from C++ however, compiling with g++, yields the > following compiling error: > > examples/example_server.c: In function ‘int generic_handler(const char*, > const char*, lo_arg**, int, void*, void*)’: > examples/example_server.c:82:36: error: invalid conversion from ‘char’ > to ‘lo_type’ > examples/example_server.c:82:36: error: initializing argument 1 of ‘void > lo_arg_pp(lo_type, void*)’ > > Researching I found this: In C, an enum (e.g. lo_type) is always of type > int. Thus, an implicit type-cast is performed. In C++, enum is a > distinct type and implicit conversion is not allowed. Making the cast > explicit makes the code work in both C and C++, like so: > > lo_arg_pp((lo_type) types[i], argv[i]); > > Now I see that this is an example C code and maybe even a C++ programmer > should be aware of that difference. But it's quite nasty so I'd suggest > changing the example code to the above line or add a comment for naive > C++ programmers like I am ;-) Hi, Great suggestion. I had to think about whether it was worth changing, but I think you're right, it's a tiny change and could resolve some confusion for newcomers. Committed! > I very much like liblo. It's very straightforward. Glad to hear it! I can tell you that there are in fact some shiny new C++ bindings coming down the line ;) Steve |