Re: Cautionary tale: bad NTP client, bad NTP clock, bad date handling, C ints

Ivan Sergio Borgonovo <[email protected]>
Newsgroups gmane.org.user-groups.linux.cabal
Organization http://www.WebThatWorks.it
Message-ID <[email protected]>

On 3/27/24 2:01 AM, Rick Moen wrote:

> The 2038 problem happens because when the first bit of a 32-bit value is
> 1 and you use it as a signed integer, it’s interpreted as a negative
> number in 2’s complement representation. But C has no protection from
> treating the same value as signed in some contexts and unsigned in
> others. If you start with a signed 32-bit integer with the value -1, it
> is represented in memory as 0xFFFFFFFF. If you then use it as an
> unsigned integer, it becomes the value 4,294,967,296.

I'm once again asking are we here to bash C for no reason?

int main(void) {
   int i = 3;
   unsigned int j = 2;
   int r;
   r = i + j;
}

gcc -Wsign-conversion i.c
i.c: In function ‘main’:
i.c:5:39: warning: conversion to ‘unsigned int’ from ‘int’ may change 
the sign of the result [-Wsign-conversion]
     5 |                                 r = i + j;
       |                                       ^
i.c:5:37: warning: conversion to ‘int’ from ‘unsigned int’ may change 
the sign of the result [-Wsign-conversion]
     5 |                                 r = i + j;
       |

-- 
Ivan Sergio Borgonovo
https://www.webthatworks.it https://www.borgonovo.net



_______________________________________________
conspire mailing list
[email protected]
http://linuxmafia.com/mailman/listinfo/conspire
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.