ludocode / mpack

MPack - A C encoder/decoder for the MessagePack serialization format / msgpack.org[C]
MIT License
521 stars 82 forks source link

Compile error with specific config #66

Closed dofuuz closed 5 years ago

dofuuz commented 5 years ago

When mpack.h included from .cpp, defining #define MPACK_WRITER 0 in config causing compile error.

src\mpack.h:3253:31: error: variable or field 'mpack_write' declared void
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int8_t value) {
                               ^~~~~~~~~~~~~~
src\mpack.h:3253:31: error: 'mpack_writer_t' was not declared in this scope
src\mpack.h:3253:31: note: suggested alternative: 'mpack_error_t'
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int8_t value) {
                               ^~~~~~~~~~~~~~
                               mpack_error_t
src\mpack.h:3253:47: error: 'writer' was not declared in this scope
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int8_t value) {
                                               ^~~~~~
src\mpack.h:3253:47: note: suggested alternative: 'fwrite'
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int8_t value) {
                                               ^~~~~~
                                               fwrite
src\mpack.h:3253:62: error: expected primary-expression before 'value'
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int8_t value) {
                                                              ^~~~~
src\mpack.h:3257:31: error: variable or field 'mpack_write' declared void
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int16_t value) {
                               ^~~~~~~~~~~~~~
src\mpack.h:3257:31: error: 'mpack_writer_t' was not declared in this scope
src\mpack.h:3257:31: note: suggested alternative: 'mpack_error_t'
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int16_t value) {
                               ^~~~~~~~~~~~~~
                               mpack_error_t
src\mpack.h:3257:47: error: 'writer' was not declared in this scope
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int16_t value) {
                                               ^~~~~~
src\mpack.h:3257:47: note: suggested alternative: 'fwrite'
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int16_t value) {
                                               ^~~~~~
                                               fwrite
src\mpack.h:3257:63: error: expected primary-expression before 'value'
 MPACK_INLINE void mpack_write(mpack_writer_t* writer, int16_t value) {
                                                               ^~~~~
...
...

possible fix:

in mpack.h(v1.0 amalgamated) line 3239 from

#if defined(__cplusplus) || defined(MPACK_DOXYGEN)

to

#if (MPACK_WRITER && defined(__cplusplus)) || defined(MPACK_DOXYGEN)
ludocode commented 5 years ago

Fixed in 93ec9cb818548e0dd8d0e56f5fb7a8bc312c41b8. Thanks for the bug report! I've added a unit test variant to ensure that C++ will always compile with disabled features.

The fix will be included in the next release. You can generate a new amalgamation package from the latest source using tools/amalgamate.sh.