radarsat1 / liblo

liblo is an implementation of the Open Sound Control protocol for POSIX systems
GNU Lesser General Public License v2.1
192 stars 60 forks source link

VS2017 compiliation issues with empty struct definitions and <BaseTsd.h> #115

Closed johnty closed 3 years ago

johnty commented 3 years ago

I have two minor things that result in issues with the VS2017 compiler, and will likely be the same with newer ones as well. In general, the CMake generated project will compile the library fine, but when the actual example C applications are built, we see errors for all the empty struct defs, such as:

typedef struct loaddress {} *lo_address;

"Error C2016: C requires that a struct or union has at least one member".

This doesn't happen for .cpp files, or if you force the compiler to treat everything in C++ mode with the /Tp switch (C/C++ Project properties->Advanced->Compile As setting)

My understanding is that the empty struct definition is only valid in the GNU compiler since it supports this non-standard extension of having nothing in the {}.

For the above (and similar definitions), it looks like this is the way to define it:

typedef struct lo_address_  *lo_address; //OK
typedef struct lo_address_ {}  *lo_address; //Not OK in C mode, OK in C++ mode

The second thing is it looks like the _MSC_VER toggled typedef for ssize_t needs to #include <BaseTsd.h> right before it to actually compile. Doesn't raise any issues when compiling the library itself, but I noticed it when trying to compile something else that depends on it. Not sure if its better to treat this at the project settings level or just in the code here as I have done...