codelite icon indicating copy to clipboard operation
codelite copied to clipboard

Fix warning about `printf`:

Open Jarod42 opened this issue 1 year ago • 2 comments

  • warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type std::size_t.

Jarod42 avatar Jul 05 '24 15:07 Jarod42

Why not %zu instead? :)

Eric-01 avatar Jul 05 '24 19:07 Eric-01

Not familiar enough with printf format. I know that std::size_t might be of different size, warning suggests %ld as fix, so wrong for other size. Not sure neither if %zu is supported by all compiler...

Jarod42 avatar Jul 05 '24 20:07 Jarod42

Testing via GodBolt it seems it should be supported on: Clang 5, GCC 5, djgpp 5.5, icc 16, icx 2021, MSVC 19, nvc++ 22, FRC, TI CL430, Zapcc

It appears that it's more common for compilers to not support C++17 then %zu.

AJenbo avatar Jul 06 '24 23:07 AJenbo