mirror of https://github.com/ecmwf/eccodes.git
Examples: use '%zu' in the format string for size_t
This commit is contained in:
parent
def66fe512
commit
55e9287fab
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue