Open kilianmh opened 1 month ago
I am not very interested for C90 compatibility, but I will merge a PR if it it has no disadvantages.
sds.c:640:52: warning: ISO C90 does not support ‘long long’ [-Wlong-long]
How would you workaround this?
How would you workaround this?
Most issues can be solved with conditional compilation
such as:
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
long long num;
#else
long num;
#endif
This will have no runtime disadvantage, but the code will be bloated somewhat.
The only issue where it's not clear what to do is that C90 does not support flexible array members. We could use a pointer to the array:
struct __attribute__ ((__packed__)) sdshdr5 {
unsigned char flags; /* 3 lsb of type, and 5 msb of string length */
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
char buf[];
#else
char *buf;
#endif
};
But then we have to manually allocate and deallocate the memory.
There was an issue in the original library for
C90
compliance here: https://github.com/antirez/sds/issues/74For a utility library like
sds
it would be nice to be compliant even with older C standards and it looks like there are not that many changes needed.What do you think? @jcorporation @dagostinelli If you like the idea, I can submit a PR.