From 55e9287fab6e175923845d13495d49eec6f307cd Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 21 Dec 2022 11:43:38 +0000 Subject: [PATCH] Examples: use '%zu' in the format string for size_t --- examples/C/bufr_copy_data.c | 2 +- examples/C/bufr_expanded.c | 2 +- examples/C/bufr_get_string_array.c | 2 +- examples/C/bufr_keys_iterator.c | 2 +- examples/C/bufr_read_temp.c | 2 +- examples/C/grib_ensemble_index.c | 4 ++-- examples/C/grib_index.c | 8 ++++---- examples/C/grib_iterator_bitmap.c | 2 +- examples/C/grib_list.c | 6 +++--- examples/C/new_sample.c | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/C/bufr_copy_data.c b/examples/C/bufr_copy_data.c index 589a7de1b..3bc8c7a39 100644 --- a/examples/C/bufr_copy_data.c +++ b/examples/C/bufr_copy_data.c @@ -93,7 +93,7 @@ int main(int argc, char* argv[]) printf("Copied %s\n", keys[i]); free(keys[i]); } - printf("Total number of copied keys = %lu\n", (unsigned long)nkeys); + printf("Total number of copied keys = %zu\n", nkeys); free(keys); codes_handle_delete(h); diff --git a/examples/C/bufr_expanded.c b/examples/C/bufr_expanded.c index 838dd70a6..6d103f68f 100644 --- a/examples/C/bufr_expanded.c +++ b/examples/C/bufr_expanded.c @@ -57,7 +57,7 @@ int main(int argc, char* argv[]) /* get the size of the values array*/ CODES_CHECK(codes_get_size(h, "numericValues", &values_len), 0); - printf(" number of expanded values: %lu\n", (unsigned long)values_len); + printf(" number of expanded values: %zu\n", values_len); /* allocate array for data values */ values = (double*)malloc(values_len * sizeof(double)); diff --git a/examples/C/bufr_get_string_array.c b/examples/C/bufr_get_string_array.c index 43f499074..5568f924a 100644 --- a/examples/C/bufr_get_string_array.c +++ b/examples/C/bufr_get_string_array.c @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) for (i = 0; i < size; ++i) { printf("%s\n", strArray[i]); } - printf("stationOrSiteName string array size = %lu\n", (unsigned long)size); + printf("stationOrSiteName string array size = %zu\n", size); /* free allocated arrays */ for (i = 0; i < size; ++i) diff --git a/examples/C/bufr_keys_iterator.c b/examples/C/bufr_keys_iterator.c index 1f739078d..47770e257 100644 --- a/examples/C/bufr_keys_iterator.c +++ b/examples/C/bufr_keys_iterator.c @@ -98,7 +98,7 @@ int main(int argc, char* argv[]) } else { /* for arrays */ - printf("(array of %lu)\n", (unsigned long)klen); + printf("(array of %zu)\n", klen); } } diff --git a/examples/C/bufr_read_temp.c b/examples/C/bufr_read_temp.c index 86e84e999..baedebea9 100644 --- a/examples/C/bufr_read_temp.c +++ b/examples/C/bufr_read_temp.c @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) snprintf(key_name, sizeof(key_name), "/verticalSoundingSignificance=4/pressure"); CODES_CHECK(codes_get_size(h, key_name, &sigt_len), 0); - printf("Number of T significant levels: %lu\n", (unsigned long)sigt_len); + printf("Number of T significant levels: %zu\n", sigt_len); /* allocate memory for the values to be read. Each * parameter must have the same number of values. */ diff --git a/examples/C/grib_ensemble_index.c b/examples/C/grib_ensemble_index.c index aab96f64d..1e86aae0b 100644 --- a/examples/C/grib_ensemble_index.c +++ b/examples/C/grib_ensemble_index.c @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) /* get size of "paramId" list */ CODES_CHECK(codes_index_get_size(index, "paramId", ¶mIdSize), 0); - printf("grib contains %lu different parameters\n", (unsigned long)paramIdSize); + printf("grib contains %zu different parameters\n", paramIdSize); /* allocate memory for "paramId" list */ paramId = (char**)malloc(paramIdSize * sizeof(char*)); /* get list of "paramId" */ @@ -47,7 +47,7 @@ int main(int argc, char* argv[]) /* get size of ensemble number list */ CODES_CHECK(codes_index_get_size(index, "number", &numberSize), 0); - printf("GRIB contains %lu different ensemble members\n", (unsigned long)numberSize); + printf("GRIB contains %zu different ensemble members\n", numberSize); /* allocate memory for ensemble number list */ number = (long*)malloc(numberSize * sizeof(long)); /* get list of ensemble numbers */ diff --git a/examples/C/grib_index.c b/examples/C/grib_index.c index 858757951..c93ef5b8f 100644 --- a/examples/C/grib_index.c +++ b/examples/C/grib_index.c @@ -64,7 +64,7 @@ int main(int argc, char* argv[]) /* get the list of distinct steps from the index */ /* the list is in ascending order */ CODES_CHECK(codes_index_get_long(index, "step", steps, &stepSize), 0); - printf("stepSize=%ld\n", (long)stepSize); + printf("stepSize=%zu\n", stepSize); for (i = 0; i < stepSize; i++) printf("%ld ", steps[i]); printf("\n"); @@ -75,7 +75,7 @@ int main(int argc, char* argv[]) if (!levels) exit(1); /*same as for "step"*/ CODES_CHECK(codes_index_get_long(index, "level", levels, &levelSize), 0); - printf("levelSize=%ld\n", (long)levelSize); + printf("levelSize=%zu\n", levelSize); for (i = 0; i < levelSize; i++) printf("%ld ", levels[i]); printf("\n"); @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) if (!numbers) exit(1); /*same as for "step"*/ CODES_CHECK(codes_index_get_long(index, "number", numbers, &numberSize), 0); - printf("numberSize=%ld\n", (long)numberSize); + printf("numberSize=%zu\n", numberSize); for (i = 0; i < numberSize; i++) printf("%ld ", numbers[i]); printf("\n"); @@ -97,7 +97,7 @@ int main(int argc, char* argv[]) if (!shortName) exit(1); /*same as for "step"*/ CODES_CHECK(codes_index_get_string(index, "shortName", shortName, &shortNameSize), 0); - printf("shortNameSize=%ld\n", (long)shortNameSize); + printf("shortNameSize=%zu\n", shortNameSize); for (i = 0; i < shortNameSize; i++) printf("%s ", shortName[i]); printf("\n"); diff --git a/examples/C/grib_iterator_bitmap.c b/examples/C/grib_iterator_bitmap.c index 6cf21b1d1..5060dc43c 100644 --- a/examples/C/grib_iterator_bitmap.c +++ b/examples/C/grib_iterator_bitmap.c @@ -55,7 +55,7 @@ int main(int argc, char** argv) CODES_CHECK(codes_get_size(h, "bitmap", &bmp_len), 0); bitmap = (long*)malloc(bmp_len * sizeof(long)); CODES_CHECK(codes_get_long_array(h, "bitmap", bitmap, &bmp_len), 0); - printf("Bitmap is present. Num = %lu\n", (unsigned long)bmp_len); + printf("Bitmap is present. Num = %zu\n", bmp_len); } /* sanity check. Number of values must match number in bitmap */ CODES_CHECK(codes_get_size(h, "values", &values_len), 0); diff --git a/examples/C/grib_list.c b/examples/C/grib_list.c index 403d0ce42..c5e1e71f0 100644 --- a/examples/C/grib_list.c +++ b/examples/C/grib_list.c @@ -65,7 +65,7 @@ int main(int argc, char** argv) /* get as a long*/ CODES_CHECK(codes_get_size(h, "scaledValueOfCentralWaveNumber", &count), 0); - printf("count=%ld\n", (long)count); + printf("count=%zu\n", count); assert(count < sizeof(values) / sizeof(values[0])); @@ -74,7 +74,7 @@ int main(int argc, char** argv) assert(size == count); for (i = 0; i < count; i++) { - printf("scaledValueOfCentralWaveNumber %lu = %ld\n", (unsigned long)i, values[i]); + printf("scaledValueOfCentralWaveNumber %zu = %ld\n", i, values[i]); if (i == 0) assert(values[i] == 26870); if (i == 1) assert(values[i] == 9272); } @@ -91,7 +91,7 @@ int main(int argc, char** argv) CODES_CHECK(codes_get_long_array(h, "scaledValueOfCentralWaveNumber", new_values, &size), 0); assert(size == count); for (i = 0; i < count; i++) { - printf("Now scaledValueOfCentralWaveNumber %lu = %ld\n", (unsigned long)i, new_values[i]); + printf("Now scaledValueOfCentralWaveNumber %zu = %ld\n", i, new_values[i]); assert(new_values[i] == (i + 1000)); } diff --git a/examples/C/new_sample.c b/examples/C/new_sample.c index 0e483c472..529b52b29 100644 --- a/examples/C/new_sample.c +++ b/examples/C/new_sample.c @@ -233,7 +233,7 @@ int main(int argc, char** argv) size = 496; vdouble = (double*)calloc(size, sizeof(double)); if (!vdouble) { - fprintf(stderr, "failed to allocate %lu bytes\n", (unsigned long)(size * sizeof(double))); + fprintf(stderr, "failed to allocate %zu bytes\n", size * sizeof(double)); exit(1); }