Re: What is your opinion about unsigned int u = -2 ?

Liste des GroupesRevenir à l c 
Sujet : Re: What is your opinion about unsigned int u = -2 ?
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.c
Date : 03. Aug 2024, 14:36:23
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v8l887$3edtr$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Mozilla Thunderbird
-------- Mensagem encaminhada --------
Assunto: Re: What is your opinion about unsigned int u = -2 ?
Data: Fri, 02 Aug 2024 19:29:27 -0700
De: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Organização: None to speak of
Grupos de notícias: comp.lang.c
Referências: <v8dfo9$1k7cg$1@dont-email.me> <pan$d2c8a$8c54ac9f$29a202e0$12c6ce86@invalid.invalid> <87bk2cecan.fsf@bsb.me.uk> <v8inds$2qpqh$1@dont-email.me> <v8iqnr$7l3c$1@news.xmission.com> <v8irje$2rolg$1@dont-email.me> <87r0b6g3qx.fsf@nosuchdomain.example.com> <v8jbj5$2us0r$4@dont-email.me> <v8jvln$33atp$1@dont-email.me> <v8k055$33fcl$1@dont-email.me> <87cymqfl3m.fsf@nosuchdomain.example.com> <v8k2ck$33nca$2@dont-email.me>
Thiago Adams <thiago.adams@gmail.com> writes:
 > Em 8/2/2024 10:31 PM, Keith Thompson escreveu:
 >> Thiago Adams <thiago.adams@gmail.com> 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
Since 18446744073709551615 is 2**64-1, it's outside the range of any
signed integer type in typical implementations.  Since unsuffixed
integer constants are of some signed type (since C99), that constant is
likely to cause problems.  You could write 18446744073709551615ull.
That's a rather odd warning.  In C90, an unsuffixed integer constant's
type was the first of (int, long int, unsigned long int) in which its
value would fit.  In C99 and later, an unsuffixed integer constant is of
type int, long int, or long long int, *never* of any unsigned type.
Since 18446744073709551615 exceeds ULLONG_MAX (assuming 64 bits),
apparently gcc treats it as having an unsigned type as an extension.
(My quick experiment indicates that, at least on my system,
18446744073709551615 is of type __int128 and, bizarrely,
18446744073709551616 is of type int with the value 0.  This seems
like a bug.)
 > 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."
I realized now I read "integer constants" as "int constants" that is very diferent! Thanks for the explanation.
----
I checked and 18446744073709551615 is not unsigned long long
static_assert(TYPE_IS(18446744073709551615, unsigned long long));
https://godbolt.org/z/vnzWWxvjr
 >"In C99 and later, an unsuffixed integer constant is of
 >type int, long int, or long long int, *never* of any unsigned type."
I think this should be reviewed before they constexpr was added in C.
I am fixing my constant expression evaluation in cake and I will share the code of "old" constant expressions and new constexpr. So constexpr does not have restriction on signed types only.

Date Sujet#  Auteur
31 Jul 24 * What is your opinion about unsigned int u = -2 ?56Thiago Adams
31 Jul 24 +* Re: What is your opinion about unsigned int u = -2 ?7Ben Bacarisse
11 Aug 24 i`* Re: What is your opinion about unsigned int u = -2 ?6Tim Rentsch
11 Aug 24 i `* Re: What is your opinion about unsigned int u = -2 ?5Vir Campestris
11 Aug 24 i  +- Re: What is your opinion about unsigned int u = -2 ?1Richard Damon
11 Aug 24 i  +* Re: What is your opinion about unsigned int u = -2 ?2James Kuyper
12 Aug 24 i  i`- Re: What is your opinion about unsigned int u = -2 ?1Vir Campestris
12 Aug 24 i  `- Re: What is your opinion about unsigned int u = -2 ?1Tim Rentsch
31 Jul 24 +- Re: What is your opinion about unsigned int u = -2 ?1James Kuyper
1 Aug 24 `* Re: What is your opinion about unsigned int u = -2 ?47Blue-Maned_Hawk
1 Aug 24  +* Re: What is your opinion about unsigned int u = -2 ?45Ben Bacarisse
2 Aug 24  i`* Re: What is your opinion about unsigned int u = -2 ?44Thiago Adams
2 Aug 24  i `* Re: What is your opinion about unsigned int u = -2 ?43Kenny McCormack
2 Aug 24  i  +* Re: What is your opinion about unsigned int u = -2 ?34Bart
2 Aug 24  i  i+- Re: What is your opinion about unsigned int u = -2 ?1Ben Bacarisse
2 Aug 24  i  i+* Re: What is your opinion about unsigned int u = -2 ?2Thiago Adams
2 Aug 24  i  ii`- Re: What is your opinion about unsigned int u = -2 ?1Thiago Adams
2 Aug 24  i  i+* Re: What is your opinion about unsigned int u = -2 ?29Keith Thompson
2 Aug 24  i  ii+* Re: What is your opinion about unsigned int u = -2 ?27James Kuyper
3 Aug 24  i  iii+* Re: What is your opinion about unsigned int u = -2 ?19Thiago Adams
3 Aug 24  i  iiii+* Re: What is your opinion about unsigned int u = -2 ?8Thiago Adams
3 Aug 24  i  iiiii`* Re: What is your opinion about unsigned int u = -2 ?7Keith Thompson
3 Aug 24  i  iiiii `* Re: What is your opinion about unsigned int u = -2 ?6Thiago Adams
3 Aug 24  i  iiiii  `* Re: What is your opinion about unsigned int u = -2 ?5Keith Thompson
3 Aug 24  i  iiiii   `* Re: What is your opinion about unsigned int u = -2 ?4Thiago Adams
4 Aug 24  i  iiiii    `* Re: What is your opinion about unsigned int u = -2 ?3Keith Thompson
4 Aug 24  i  iiiii     `* Re: What is your opinion about unsigned int u = -2 ?2Thiago Adams
4 Aug 24  i  iiiii      `- Re: What is your opinion about unsigned int u = -2 ?1Thiago Adams
3 Aug 24  i  iiii`* Re: What is your opinion about unsigned int u = -2 ?10Keith Thompson
3 Aug 24  i  iiii `* Re: What is your opinion about unsigned int u = -2 ?9Thiago Adams
3 Aug 24  i  iiii  `* Re: What is your opinion about unsigned int u = -2 ?8Keith Thompson
3 Aug 24  i  iiii   `* Re: What is your opinion about unsigned int u = -2 ?7Thiago Adams
3 Aug 24  i  iiii    `* Re: What is your opinion about unsigned int u = -2 ?6Keith Thompson
3 Aug 24  i  iiii     +* Re: What is your opinion about unsigned int u = -2 ?3David Brown
3 Aug 24  i  iiii     i`* Re: What is your opinion about unsigned int u = -2 ?2Thiago Adams
4 Aug 24  i  iiii     i `- Re: What is your opinion about unsigned int u = -2 ?1Keith Thompson
25 Aug 24  i  iiii     `* Re: What is your opinion about unsigned int u = -2 ?2dave thompson 2
25 Aug 24  i  iiii      `- Re: What is your opinion about unsigned int u = -2 ?1Keith Thompson
3 Aug 24  i  iii`* Re: What is your opinion about unsigned int u = -2 ?7David Brown
3 Aug 24  i  iii `* Re: What is your opinion about unsigned int u = -2 ?6Thiago Adams
3 Aug 24  i  iii  +* Re: What is your opinion about unsigned int u = -2 ?4Thiago Adams
4 Aug 24  i  iii  i`* Re: What is your opinion about unsigned int u = -2 ?3Keith Thompson
11 Aug 24  i  iii  i `* Re: What is your opinion about unsigned int u = -2 ?2Tim Rentsch
11 Aug 24  i  iii  i  `- Re: What is your opinion about unsigned int u = -2 ?1Keith Thompson
4 Aug 24  i  iii  `- Re: What is your opinion about unsigned int u = -2 ?1Keith Thompson
9 Aug 24  i  ii`- Re: What is your opinion about unsigned int u = -2 ?1Bonita Montero
3 Aug 24  i  i`- Re: What is your opinion about unsigned int u = -2 ?1David Brown
4 Aug 24  i  `* Re: What is your opinion about unsigned int u = -2 ?8Bonita Montero
8 Aug 24  i   `* Re: What is your opinion about unsigned int u = -2 ?7Lawrence D'Oliveiro
8 Aug 24  i    `* Re: What is your opinion about unsigned int u = -2 ?6David Brown
9 Aug 24  i     `* Re: What is your opinion about unsigned int u = -2 ?5Bonita Montero
9 Aug 24  i      `* Re: What is your opinion about unsigned int u = -2 ?4David Brown
9 Aug 24  i       +* Re: What is your opinion about unsigned int u = -2 ?2Bonita Montero
9 Aug 24  i       i`- Re: What is your opinion about unsigned int u = -2 ?1David Brown
10 Aug 24  i       `- Re: What is your opinion about unsigned int u = -2 ?1Richard Damon
4 Aug 24  `- Re: What is your opinion about unsigned int u = -2 ?1Bonita Montero

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal