[gdal-dev] Printing a size_t variable on all github platforms ?

Even Rouault even.rouault at spatialys.com
Mon Apr 15 11:02:14 PDT 2024


Andrew,

some hints at 
https://stackoverflow.com/questions/44382862/how-to-printf-a-size-t-without-warning-in-mingw-w64-gcc-7-1

Otherwise an alternative is to cast to uint64_t and use PRIu64

Even

Le 15/04/2024 à 19:49, Andrew C Aitchison via gdal-dev a écrit :
>
> I am trying to print a size_t variable* with CPLDebug, but
> am struggling to find a format that works for all the guthub builds.
>
> The main problem is that the "build-windows-msys2-mingw" build
> does not support the format option %zu
>
> ../../../frmts/vrc/VRC.cpp:159:47: error: unknown conversion type 
> character 'z' in format [-Werror=format=]
>   159 |                  "VRC_png_read_data_fn(%p %p %zu) reached end 
> of data",
>       |                                               ^
> https://github.com/andrew-aitchison/gdal/actions/runs/8691997363/job/23835554972 
>
> lines 586-8.
>
> Since size_t is usually an unsigned int on 64-bit systems and
> an unsigned long on 32-bit systems ("build-windows-msys2-mingw"
> and "Alpine, gcc 32-bit") I cannot use %u or %lu either,
> without conditional compiling.
> I don't see any helpful definition in <inttypes.h> either
>
> Am I missing a way of printing a size_t ?
> I suppose I could cast it to an unsigned long (long?) and hope.
>
> Thanks,
>
> ---  Pedantry
>
> I'm ultimately trying to print "myVector.size()"
> which is a "std::vector<...>::size_type", which
> https://stackoverflow.com/questions/918567/size-t-vs-containersize-type
> says *may* be be different from a size_t ... but
>   https://en.cppreference.com/w/cpp/types/size_t
> says that std::size_t is big enough (or the type is ill-formed).
>
-- 
http://www.spatialys.com
My software is free, but my time generally not.



More information about the gdal-dev mailing list