diff options
author | Kelvin Lee <kiyolee@gmail.com> | 2020-11-05 22:05:54 +1100 |
---|---|---|
committer | Kelvin Lee <kiyolee@gmail.com> | 2020-11-05 22:05:54 +1100 |
commit | 1d8201c6562c0efd8db7ed4214dc19efe617e6f6 (patch) | |
tree | 7f4b9cd5f619bae168c5e72ee278ef50833a6b27 | |
parent | a740f15c17ef7956b1493d8d1f800896c1e60bad (diff) | |
download | jansson-1d8201c6562c0efd8db7ed4214dc19efe617e6f6.zip jansson-1d8201c6562c0efd8db7ed4214dc19efe617e6f6.tar.gz jansson-1d8201c6562c0efd8db7ed4214dc19efe617e6f6.tar.bz2 |
Print size_t properly with C11 %zd support.
-rw-r--r-- | examples/simple_parse.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/examples/simple_parse.c b/examples/simple_parse.c index 4554e4f..728416d 100644 --- a/examples/simple_parse.c +++ b/examples/simple_parse.c @@ -30,7 +30,7 @@ void print_json(json_t *root); void print_json_aux(json_t *element, int indent); void print_json_indent(int indent); -const char *json_plural(int count); +const char *json_plural(size_t count); void print_json_object(json_t *element, int indent); void print_json_array(json_t *element, int indent); void print_json_string(json_t *element, int indent); @@ -80,7 +80,7 @@ void print_json_indent(int indent) { } } -const char *json_plural(int count) { return count == 1 ? "" : "s"; } +const char *json_plural(size_t count) { return count == 1 ? "" : "s"; } void print_json_object(json_t *element, int indent) { size_t size; @@ -90,7 +90,11 @@ void print_json_object(json_t *element, int indent) { print_json_indent(indent); size = json_object_size(element); - printf("JSON Object of %ld pair%s:\n", size, json_plural(size)); +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + printf("JSON Object of %zd pair%s:\n", size, json_plural(size)); +#else + printf("JSON Object of %lld pair%s:\n", (long long)size, json_plural(size)); +#endif json_object_foreach(element, key, value) { print_json_indent(indent + 2); printf("JSON Key: \"%s\"\n", key); @@ -103,7 +107,11 @@ void print_json_array(json_t *element, int indent) { size_t size = json_array_size(element); print_json_indent(indent); - printf("JSON Array of %ld element%s:\n", size, json_plural(size)); +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + printf("JSON Array of %zd element%s:\n", size, json_plural(size)); +#else + printf("JSON Array of %lld element%s:\n", (long long)size, json_plural(size)); +#endif for (i = 0; i < size; i++) { print_json_aux(json_array_get(element, i), indent + 2); } |