Deutsch English Français Italiano |
<v8e9ks$1oo9l$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!feeds.phibee-telecom.net!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: What is your opinion about unsigned int u = -2 ? Date: Wed, 31 Jul 2024 17:17:15 -0400 Organization: A noiseless patient Spider Lines: 23 Message-ID: <v8e9ks$1oo9l$1@dont-email.me> References: <v8dfo9$1k7cg$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Wed, 31 Jul 2024 23:17:17 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c000513bafec376398aeed29baf02289"; logging-data="1859893"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19du7xsLzD6OkR4nJN2Vp7f17VhbLmU7o0=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:r+VCmUtrnqxV9LKTuyp4sl+lbEw= In-Reply-To: <v8dfo9$1k7cg$1@dont-email.me> Content-Language: en-US Bytes: 1690 Thiago Adams <thiago.adams@gmail.com> writes: > What is your opinion about this: > > unsigned int u1 = -1; > > Generally -1 is used to get the maximum value. > > Is this guaranteed to work? Yes. "... the value is converted by repeatedly adding or subtracting one more than the maximum value that can be represented in the new type until the value is in the range of the new type." (6.3.1.3p2). In practice, there's better ways than repeated addition, but that's how the conversion is defined. > How about this one? > > unsigned int u2 = -2; That is guaranteed to produce 1 less than the maximum value.