update warning unnamed structs/unions

fix warning: ISO C99 doesn't support unnamed structs/unions
This commit is contained in:
PetersSharp 2018-04-26 13:47:54 +03:00 committed by GitHub
parent 2e98dd7e63
commit 421fbd3501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 15 deletions

View File

@ -1,4 +1,7 @@
# tiny-json # tiny-json
- update warning: "ISO C99 doesn't support unnamed structs/unions"
tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable. tiny-json is a versatile and easy to use json parser in C suitable for embedded systems. It is fast, robust and portable.
It is not only a tokenizer. You can get data in string format or get the primitives values in C type variables without performance loss. It is not only a tokenizer. You can get data in string format or get the primitives values in C type variables without performance loss.

View File

@ -30,7 +30,7 @@ typedef struct jsonPool_s {
/* Search a property by its name in a JSON object. */ /* Search a property by its name in a JSON object. */
json_t const* json_getProperty( json_t const* obj, char const* property ) { json_t const* json_getProperty( json_t const* obj, char const* property ) {
json_t const* sibling; json_t const* sibling;
for( sibling = obj->u.child; sibling; sibling = sibling->sibling ) for( sibling = obj->u.c.child; sibling; sibling = sibling->sibling )
if ( sibling->name && !strcmp( sibling->name, property ) ) if ( sibling->name && !strcmp( sibling->name, property ) )
return sibling; return sibling;
return 0; return 0;
@ -63,7 +63,7 @@ json_t const* json_create( char* str, json_t mem[], unsigned int qty ) {
json_t* obj = poolInit( &pool ); json_t* obj = poolInit( &pool );
obj->name = 0; obj->name = 0;
obj->sibling = 0; obj->sibling = 0;
obj->u.child = 0; obj->u.c.child = 0;
ptr = objValue( ptr, obj, &pool ); ptr = objValue( ptr, obj, &pool );
if ( !ptr ) return 0; if ( !ptr ) return 0;
return obj; return obj;
@ -300,12 +300,12 @@ static char* numValue( char* ptr, json_t* property ) {
* @param property The handler of the property to be added. */ * @param property The handler of the property to be added. */
static void add( json_t* obj, json_t* property ) { static void add( json_t* obj, json_t* property ) {
property->sibling = 0; property->sibling = 0;
if ( !obj->u.child ){ if ( !obj->u.c.child ){
obj->u.child = property; obj->u.c.child = property;
obj->u.last_child = property; obj->u.c.last_child = property;
} else { } else {
obj->u.last_child->sibling = property; obj->u.c.last_child->sibling = property;
obj->u.last_child = property; obj->u.c.last_child = property;
} }
} }
@ -316,7 +316,7 @@ static void add( json_t* obj, json_t* property ) {
* @retval Null pointer if any error occur. */ * @retval Null pointer if any error occur. */
static char* objValue( char* ptr, json_t* obj, jsonPool_t* pool ) { static char* objValue( char* ptr, json_t* obj, jsonPool_t* pool ) {
obj->type = JSON_OBJ; obj->type = JSON_OBJ;
obj->u.child = 0; obj->u.c.child = 0;
obj->sibling = 0; obj->sibling = 0;
ptr++; ptr++;
for(;;) { for(;;) {
@ -349,14 +349,14 @@ static char* objValue( char* ptr, json_t* obj, jsonPool_t* pool ) {
switch( *ptr ) { switch( *ptr ) {
case '{': case '{':
property->type = JSON_OBJ; property->type = JSON_OBJ;
property->u.child = 0; property->u.c.child = 0;
property->sibling = obj; property->sibling = obj;
obj = property; obj = property;
++ptr; ++ptr;
break; break;
case '[': case '[':
property->type = JSON_ARRAY; property->type = JSON_ARRAY;
property->u.child = 0; property->u.c.child = 0;
property->sibling = obj; property->sibling = obj;
obj = property; obj = property;
++ptr; ++ptr;

View File

@ -43,10 +43,10 @@ typedef struct json_s {
char const* name; char const* name;
union { union {
char const* value; char const* value;
struct { struct {
struct json_s* child; struct json_s* child;
struct json_s* last_child; struct json_s* last_child;
}; } c;
} u; } u;
jsonType_t type; jsonType_t type;
} json_t; } json_t;
@ -112,7 +112,7 @@ char const* json_getPropertyValue( json_t const* obj, char const* property );
* @retval The handler of the first property if there is. * @retval The handler of the first property if there is.
* @retval Null pointer if the json object has not properties. */ * @retval Null pointer if the json object has not properties. */
static inline json_t const* json_getChild( json_t const* json ) { static inline json_t const* json_getChild( json_t const* json ) {
return json->u.child; return json->u.c.child;
} }
/** Get the value of a json boolean property. /** Get the value of a json boolean property.