tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] match formats and arguments exactly


From: Vincent Lefevre
Subject: Re: [Tinycc-devel] match formats and arguments exactly
Date: Sat, 22 Jun 2019 21:45:25 +0200
User-agent: Mutt/1.12.1+22 (05d31caa) vl-117499 (2019-06-21)

On 2019-06-22 20:34:35 +0200, Michael Matz wrote:
> Hi,
> 
> On Sat, 22 Jun 2019, Vincent Lefevre wrote:
> 
> > > I don't object, but have a request: can you explore if changing
> > > the type of the respective variable, instead of adding casts, is
> > > equivalent? Especially the changes in parse_escape_string look
> > > as if that's possible. (I consider such type change only better
> > > than casts, if the former doesn't cause further casts elsewhere,
> > > of course).
> > 
> > Changing signed integers to unsigned just to avoid casts for
> > printf-like functions is a bad idea. The reason is that in
> > some expressions, using unsigned types can silently modify
> > the value of a signed type when implicitly converted to
> > unsigned.
> 
> Sure.  Which is why I said "if [changing the type] ... is equivalent".  If
> it causes above issues it isn't equivalent.

Yes, but it can be equivalent now, but the unsigned version could
trigger bug later, when new code is added.

In general, I now tend to use signed integers for integers on which
standard integer arithmetic will be done (even when the value will
always be non-negative), except when the range is not sufficient
and the unsigned version would be sufficient (for instance, an
unsigned int can represent the sum of two non-negative int), but
these are quite particular cases. And I use unsigned integers when
they are intended for bitwise operations or modular arithmetic.

Even if I use printf with %x, this has no effect on the above
decision.

-- 
Vincent Lefèvre <address@hidden> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]