[Spice-devel] [spice v3] utils: Remove the LL suffix from NSEC_PER_SEC

Uri Lublin uril at redhat.com
Wed Jun 26 10:01:54 UTC 2019


On 6/25/19 7:35 PM, Francois Gouget wrote:
> On Tue, 25 Jun 2019, Frediano Ziglio wrote:
> [...]
>>>      uint64_t foo = 1234;
>>>      spice_debug("foo=%" PRId64, foo / NSEC_PER_SEC);
> [...]
>> If you assume long long == 64 bit should not be a big problem
>> although you can still have the warning.

So, we all agree that the LL suffix is not good.
And we all agree that this patch fixes this issue.

Also if NSEC_PER_SEC is changed to be of type int64_t, then
there is no warning here.

So, the discussion is if the issue can be fixed differently,
with a prefix of (int64_t) or with INT64_C.


[...]


> I'd very much prefer the cast to be in the expression rather than hidden
> in some far away macro.

Is that true even if the cast is needed in all the expressions
that use this constant ?

Thanks,
     Uri.

> 
> For instance:
> 
>      int frames_count;
>      ...
> 
>      if (duration > NSEC_PER_SEC * drawable->frames_count / MAX_FPS) {
> 
> Anyone checking this calculation would think that there is a risk of
> overflow. And it's only when tracing NSEC_PER_SEC to utils.h that they
> would discover that NSEC_PER_SEC forces 64 bit calculation.
> 
> At least this form is clear right away:
> 
>      if (duration > ((uint64_t)NSEC_PER_SEC) * drawable->frames_count / MAX_FPS) {
> 


More information about the Spice-devel mailing list