-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can union be used to store the value? #16
Comments
It's a fair suggestion, and one that's been around a few times before. So, yes, it sure could be done, but the memory cost is worth the debug-time cost. |
Hello, I have an idea to use an union structure to store the value. Just as follows:
`// union of a cJSON value
typedef union cJSON_Value {
// suppose the size of a pointer is 4-byte. valuestring[1] may be useless.
char *valuestring[2];
int valueint[2];
double valuedouble;
} cJSON_Value;
// struct of cJSON
typedef struct cJSON {
struct cJSON _next,_prev;
struct cJSON *child;
int type;
cJSON_Value value;
char *string;
} cJSON;`
The use of union can reduce the size of a JSON on the sacrifice of the portability. So, it's just a suggestion.
The text was updated successfully, but these errors were encountered: