sds
sds copied to clipboard
sds doesn't compile as C++
There exist platforms that use a C++ compiler even for C code. Regardless of that, I think it would be a good idea to make sds compile out of the box with C++ compilers...
I've uploaded patches for that, cf. https://github.com/antirez/sds/pull/31
Uh, oh, I'm not so experienced with github. The two patches I suggest are commits
bf77d21f39e6fec3feda9cf08ce29232c4eb3d77
43e7040e7ad962f481047b4ed94402c2d798a4f6
in the lemzwerg/sds
clone.
With clang C++, fixing this issue is now a one-line change: simply replace the void*
in the definition of SDS_HDR_VAR
with struct sdshdr##T *
.
I think you are right, but there are far more issues with C++ – the concept of 'flexible array members' doesn't exist at all in the C++ standard! See the many other sds pull requests I've merged into my sds tree (lemberg/sds
); some of them are written by me, which I've also submitted to antirez. However, antirez hasn't used any of the suggested pull requests (many of them quite important IMHO). Right now, I'm too lazy to update the various pull requests to SDS 2.
I'm having this issue as well, you can't include and use sds
with C++ projects.
sds/sds.h:115:13: error: cannot initialize a variable of type 'struct sdshdr8 *' with an rvalue of type 'void *'
SDS_HDR_VAR(8,s);
^~~~~~~~~~~~~~~~
sds/sds.h:87:44: note: expanded from macro 'SDS_HDR_VAR'
#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sds/sds.h:119:13: error: cannot initialize a variable of type 'struct sdshdr16 *' with an rvalue of type 'void *'
SDS_HDR_VAR(16,s);
^~~~~~~~~~~~~~~~~
sds/sds.h:87:44: note: expanded from macro 'SDS_HDR_VAR'
#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sds/sds.h:123:13: error: cannot initialize a variable of type 'struct sdshdr32 *' with an rvalue of type 'void *'
SDS_HDR_VAR(32,s);
^~~~~~~~~~~~~~~~~
sds/sds.h:87:44: note: expanded from macro 'SDS_HDR_VAR'
#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sds/sds.h:127:13: error: cannot initialize a variable of type 'struct sdshdr64 *' with an rvalue of type 'void *'
SDS_HDR_VAR(64,s);
^~~~~~~~~~~~~~~~~
sds/sds.h:87:44: note: expanded from macro 'SDS_HDR_VAR'
#define SDS_HDR_VAR(T,s) struct sdshdr##T *sh = (void*)((s)-(sizeof(struct sdshdr##T)));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 errors generated.
The odd thing is, it looks like this is updated in Hiredis
. @antirez could you please update your library? This repository should represent the latest changes to these files.
https://github.com/redis/hiredis/blob/master/sds.h