Closed chrstphrchvz closed 3 years ago
I wonder if the casts are necessary. A smaller change seems to be sufficient to cease the warnings:
diff --git i/Tk/typemap w/Tk/typemap
index 2913885..56b581f 100644
--- i/Tk/typemap
+++ w/Tk/typemap
@@ -30,7 +30,7 @@ T_PVOBJ
STRLEN sz;
$var = ($type) SvPV((SV*)SvRV($arg),sz);
if (sz != sizeof(*$var))
- croak(\"$arg too small (%d) for $var $type (%d)\",sz,sizeof(*$var));
+ croak(\"$arg too small (%\"UVuf\") for $var $type (%\"UVuf\")\",sz,sizeof(*$var));
}
else
croak(\"$var is not an object\")
I think you have a point; . I have revised this to remove the explicit casts.UV
should be large enough for implicit casts (promotion) to work
I had read https://perldoc.perl.org/perlguts.html#Formatted-Printing-of-Size_t-and-SSize_t (since STRLEN
is MEM_SIZE
a.k.a. Size_t
), and had gotten the impression it was suggesting explicit casts, but now I wonder if that is not what it meant:
Formatted Printing of
Size_t
andSSize_t
The most general way to do this is to cast them to a UV or IV …
UV
should be large enough for implicit casts (promotion) to work
Actually, I don't think that's what's happening here. I found that a compiler will still complain if promotion were needed, e.g. if %lu
is given an unsigned int
rather than a long unsigned int
. I guess that in this case, the size of UV is just right, and no cast is necessary.
Add casts touseUV
, and"%"UVuf
format specifiers instead of"%d"
, to prevent the following compiler warnings: