Path: csiph.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: how cast works? Date: Wed, 07 Aug 2024 13:13:40 -0700 Organization: None to speak of Lines: 25 Message-ID: <87bk249jm3.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 07 Aug 2024 22:13:41 +0200 (CEST) Injection-Info: dont-email.me; posting-host="fde1ffae9f6927ccc01afbae751eb89a"; logging-data="3502686"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX180gkivnSC5Q8kNkTtADXjF" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:f288d6lwLazawuVr5FaW2KQo9zg= sha1:i9lAGbQa88z49PCva/rovhI+1pM= Xref: csiph.com comp.lang.c:387383 Thiago Adams writes: > I also would like to understand better why integer promotions were created. > > My guess..it is because the values are used in registers and there is > no "char" size register so the values are converted in a bigger type. > Is my guess correct? In the C abstract machine, there are no arithmetic operations on types narrower than int and unsigned int. If x and y are of type char, x+y has to promote both to int (or perhaps unsigned int on some weird systems) before performing the addition, because there is char+char operation. Some CPUs do have operations for narrower types, and a compiler can generate them if the results are consistent with the standard-defined semantics. The C rules are motivated by the set of operations available by typical hardware, but they've been set in stone for a long time. And it's about available operations, not about registers. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */