Examples: use '%zu' in the format string for size_t

This commit is contained in:
Shahram Najm 2022-12-21 11:43:38 +00:00
parent def66fe512
commit 55e9287fab
10 changed files with 16 additions and 16 deletions

View File

@ -93,7 +93,7 @@ int main(int argc, char* argv[])
printf("Copied %s\n", keys[i]); printf("Copied %s\n", keys[i]);
free(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); free(keys);
codes_handle_delete(h); codes_handle_delete(h);

View File

@ -57,7 +57,7 @@ int main(int argc, char* argv[])
/* get the size of the values array*/ /* get the size of the values array*/
CODES_CHECK(codes_get_size(h, "numericValues", &values_len), 0); 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 */ /* allocate array for data values */
values = (double*)malloc(values_len * sizeof(double)); values = (double*)malloc(values_len * sizeof(double));

View File

@ -56,7 +56,7 @@ int main(int argc, char* argv[])
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
printf("%s\n", strArray[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 */ /* free allocated arrays */
for (i = 0; i < size; ++i) for (i = 0; i < size; ++i)

View File

@ -98,7 +98,7 @@ int main(int argc, char* argv[])
} }
else { else {
/* for arrays */ /* for arrays */
printf("(array of %lu)\n", (unsigned long)klen); printf("(array of %zu)\n", klen);
} }
} }

View File

@ -84,7 +84,7 @@ int main(int argc, char* argv[])
snprintf(key_name, sizeof(key_name), "/verticalSoundingSignificance=4/pressure"); snprintf(key_name, sizeof(key_name), "/verticalSoundingSignificance=4/pressure");
CODES_CHECK(codes_get_size(h, key_name, &sigt_len), 0); 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 /* allocate memory for the values to be read. Each
* parameter must have the same number of values. */ * parameter must have the same number of values. */

View File

@ -39,7 +39,7 @@ int main(int argc, char* argv[])
/* get size of "paramId" list */ /* get size of "paramId" list */
CODES_CHECK(codes_index_get_size(index, "paramId", &paramIdSize), 0); CODES_CHECK(codes_index_get_size(index, "paramId", &paramIdSize), 0);
printf("grib contains %lu different parameters\n", (unsigned long)paramIdSize); printf("grib contains %zu different parameters\n", paramIdSize);
/* allocate memory for "paramId" list */ /* allocate memory for "paramId" list */
paramId = (char**)malloc(paramIdSize * sizeof(char*)); paramId = (char**)malloc(paramIdSize * sizeof(char*));
/* get list of "paramId" */ /* get list of "paramId" */
@ -47,7 +47,7 @@ int main(int argc, char* argv[])
/* get size of ensemble number list */ /* get size of ensemble number list */
CODES_CHECK(codes_index_get_size(index, "number", &numberSize), 0); 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 */ /* allocate memory for ensemble number list */
number = (long*)malloc(numberSize * sizeof(long)); number = (long*)malloc(numberSize * sizeof(long));
/* get list of ensemble numbers */ /* get list of ensemble numbers */

View File

@ -64,7 +64,7 @@ int main(int argc, char* argv[])
/* get the list of distinct steps from the index */ /* get the list of distinct steps from the index */
/* the list is in ascending order */ /* the list is in ascending order */
CODES_CHECK(codes_index_get_long(index, "step", steps, &stepSize), 0); 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++) for (i = 0; i < stepSize; i++)
printf("%ld ", steps[i]); printf("%ld ", steps[i]);
printf("\n"); printf("\n");
@ -75,7 +75,7 @@ int main(int argc, char* argv[])
if (!levels) exit(1); if (!levels) exit(1);
/*same as for "step"*/ /*same as for "step"*/
CODES_CHECK(codes_index_get_long(index, "level", levels, &levelSize), 0); 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++) for (i = 0; i < levelSize; i++)
printf("%ld ", levels[i]); printf("%ld ", levels[i]);
printf("\n"); printf("\n");
@ -86,7 +86,7 @@ int main(int argc, char* argv[])
if (!numbers) exit(1); if (!numbers) exit(1);
/*same as for "step"*/ /*same as for "step"*/
CODES_CHECK(codes_index_get_long(index, "number", numbers, &numberSize), 0); 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++) for (i = 0; i < numberSize; i++)
printf("%ld ", numbers[i]); printf("%ld ", numbers[i]);
printf("\n"); printf("\n");
@ -97,7 +97,7 @@ int main(int argc, char* argv[])
if (!shortName) exit(1); if (!shortName) exit(1);
/*same as for "step"*/ /*same as for "step"*/
CODES_CHECK(codes_index_get_string(index, "shortName", shortName, &shortNameSize), 0); 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++) for (i = 0; i < shortNameSize; i++)
printf("%s ", shortName[i]); printf("%s ", shortName[i]);
printf("\n"); printf("\n");

View File

@ -55,7 +55,7 @@ int main(int argc, char** argv)
CODES_CHECK(codes_get_size(h, "bitmap", &bmp_len), 0); CODES_CHECK(codes_get_size(h, "bitmap", &bmp_len), 0);
bitmap = (long*)malloc(bmp_len * sizeof(long)); bitmap = (long*)malloc(bmp_len * sizeof(long));
CODES_CHECK(codes_get_long_array(h, "bitmap", bitmap, &bmp_len), 0); 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 */ /* sanity check. Number of values must match number in bitmap */
CODES_CHECK(codes_get_size(h, "values", &values_len), 0); CODES_CHECK(codes_get_size(h, "values", &values_len), 0);

View File

@ -65,7 +65,7 @@ int main(int argc, char** argv)
/* get as a long*/ /* get as a long*/
CODES_CHECK(codes_get_size(h, "scaledValueOfCentralWaveNumber", &count), 0); 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])); assert(count < sizeof(values) / sizeof(values[0]));
@ -74,7 +74,7 @@ int main(int argc, char** argv)
assert(size == count); assert(size == count);
for (i = 0; i < count; i++) { 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 == 0) assert(values[i] == 26870);
if (i == 1) assert(values[i] == 9272); 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); CODES_CHECK(codes_get_long_array(h, "scaledValueOfCentralWaveNumber", new_values, &size), 0);
assert(size == count); assert(size == count);
for (i = 0; i < count; i++) { 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)); assert(new_values[i] == (i + 1000));
} }

View File

@ -233,7 +233,7 @@ int main(int argc, char** argv)
size = 496; size = 496;
vdouble = (double*)calloc(size, sizeof(double)); vdouble = (double*)calloc(size, sizeof(double));
if (!vdouble) { 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); exit(1);
} }