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

Andrew C Aitchison andrew at aitchison.me.uk
Mon Apr 15 10:49:31 PDT 2024


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).

-- 
Andrew C. Aitchison                      Kendal, UK
                    andrew at aitchison.me.uk


More information about the gdal-dev mailing list