Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Thiago Adams Newsgroups: comp.lang.c Subject: Re: What is your opinion about unsigned int u = -2 ? Date: Fri, 2 Aug 2024 22:50:11 -0300 Organization: A noiseless patient Spider Lines: 35 Message-ID: References: <87bk2cecan.fsf@bsb.me.uk> <87r0b6g3qx.fsf@nosuchdomain.example.com> <87cymqfl3m.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 03 Aug 2024 03:50:13 +0200 (CEST) Injection-Info: dont-email.me; posting-host="6ca7cab00778520cac37785ddd7f8d1f"; logging-data="3267978"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ysyYsTQOpXLPb4rLYzgylZ+8mjaYacXo=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:hWugzyqaHHd5dKNVTUZhc12Syl0= Content-Language: en-GB In-Reply-To: <87cymqfl3m.fsf@nosuchdomain.example.com> Bytes: 2675 Em 8/2/2024 10:31 PM, Keith Thompson escreveu: > Thiago Adams writes: > [...] >> It is interesting to compare constexpr with the existing constant >> expression in C that works with integers.Compilers extend to work with >> unsigned long long. >> constexpr works with the sizes as defined , for instance char. > > I'm not sure what you mean by "Compilers extend to work with > unsigned long long.". enum {C = 18446744073709551615 -1 }; // ~~~~~~~~~~~~~~~~~~~~ // ^ warning: integer constant is so large that it is unsigned https://godbolt.org/z/K7hzczETP This part "shall only have operands that are integer constants" From C23 "An integer constant expression132) shall have integer type and shall only have operands that are integer constants, named and compound literal constants of integer type, character constants, sizeof expressions whose results are integer constants, alignof expressions, and floating, named, or compound literal constants of arithmetic type that are the immediate operands of casts. Cast operators in an integer constant expression shall only convert arithmetic types to integer types, except as part of an operand to the typeof operators, sizeof operator, or alignof operator."