[Y-devel] (size_t == int)?

Aaron Kemp kempa at kwic.com
Fri Feb 20 13:50:57 GMT 2004


On Fri, 2004-02-20 at 08:28, Andrew A. Gill wrote:
> I suppose all that you need to do is add the following line
> (say, right after line 50):
> 
>     int q = s;
> 
> and change line 56, arg 2 to q.

I would be tempted to simply cast it instead of allocating more space on
the stack.  Since from printf (3) we have:

  "If the precision is given as just ‘.’, or the precision is negative,
   the precision is taken to be zero."

You can safely cast from size_t (usually an unsigned int) to an int
without worrying about (large-positive)/negative values causing bad
things to happen.  So line 56:

        printf ("%.*s\n", (int)s, d);

Would do the trick I think.  One wonders though, why printf() doesn't
take a size_t instead of an int since negative precisions are
uninteresting.

Aaron
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : https://www.y-windows.org/pipermail/y-devel/attachments/20040220/29b822a6/attachment.bin


More information about the Y-devel mailing list









2026 © www.Y-Windows.Org - All Rights Reserved