gpsd-dev
[Top][All Lists]
Advanced

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

Re: long long unsigned on 32-bit machines


From: Kai Harrekilde-Petersen
Subject: Re: long long unsigned on 32-bit machines
Date: Sun, 26 Jan 2020 15:44:30 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

My guess is that the problem lies in the bit-selection expresion: (1 << i).
The 1 is a signed int by default, so forcing i to be an uint64_t promotes the result to be 64 bit as well, so testing for bit 31 works correctly. If this is indeed the problem, use 1UL instead.

/Kai, shooting from the hip here

On 26 Jan 2020 15.21, Bernd Zeimetz wrote:

On 1/26/20 2:21 PM, Sanjeev Gupta wrote:> I think we should wait for
Bernd to chime in.

That is just the fix for the change before - unsigned long is still not
64bit on 32bit. I can't remember how I stumbled across it, but I guess
some tool pointed it out.

After looking at the code again - I have no idea why there is something
else than a simple int needed.



commit b1b555e0cb37382655a3a7cb37f2f89cb89eda7a
Author: Gary E. Miller <address@hidden>
Date:   Thu Oct 10 12:19:28 2019 -0700

     monitor_italk.c: 32-bit unsigned too small by one.

     Problem found by cpplint

diff --git a/monitor_italk.c b/monitor_italk.c
index 8da7e17ea..6ee79cbf0 100644
--- a/monitor_italk.c
+++ b/monitor_italk.c
@@ -160,11 +160,11 @@ static void display_itk_navfix(unsigned char *buf,
size_t len)
      (void)wmove(navfixwin, 11, 6);
      {
         char prn[4], satlist[38];
-       unsigned int i;
+       unsigned long i;         // unsigned long just in case ints are
32-bit
         satlist[0] = '\0';
         for (i = 0; i < 32; i++) {
             if (svlist & (1 << i)) {
-               (void)snprintf(prn, 4, "%u ", i + 1);
+               (void)snprintf(prn, 4, "%lu ", i + 1);
                 (void)strlcat(satlist, prn, sizeof(satlist));
             }
         }


--
Sanjeev




reply via email to

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