Sujet : Re: What is your opinion about unsigned int u = -2 ?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 03. Aug 2024, 02:31:25
Autres entêtes
Organisation : None to speak of
Message-ID : <87cymqfl3m.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Gnus/5.13 (Gnus v5.13)
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.".
Preprocessing expressions (used in #if conditions) are evaluated in
intmax_t or uintmax_t, but that's not the case for constant expressions
in general. For example, in :
static const signed char c = -2;
the initializer is required to be a constant expression. -2 is of type
int, which is implicitly converted to char. There are no constants of
types narrower than int, but you can write:
static const signed char c = (signed char)-2;
where `(signed char)-2` is a constant expression of type signed char.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */