0

If hi have , in C, follow expression a+b, where

signed long a;
unsigned short b;

..... wich is type of result?

I think that is unsigned long for usual conversion... But maybe not... For a machine with integer on 16 bit, short and long can have also 16 bit... So...

  1. For promotion integer b is promoted to unsigned int ... And now I have signed long + unsigned int.. Not same type...
  2. For usual conversion ... we convert signed long and unsigned int in unsigned long (tupe unsigned with rank of signed type)...

So if a = -10 and b = 120 , a + b != 0... In this case a + b = (65426)_10

this is right?

Epik
  • 47
  • 6
  • 1
    `long can have also 16 bit` well, it can't. `long` has to at least be able to represent `2,147,483,647`. It has to have at least 32-bits. – KamilCuk Feb 03 '21 at 08:42
  • "For a machine with integer on 16 bit, short and long can have also 16 bit" No. `LONG_MAX` must be at least 2^31 - 1, it is not allowed to be smaller than that. Seems all of these misconceptions originate from the impossible "16 bit long". – Lundin Feb 03 '21 at 08:46
  • @Lundin, probably the same course. :) – Devolus Feb 03 '21 at 08:53
  • @Devolus Probably not since I wrote that dupe post myself as a self-answered Q&A back in 2017? – Lundin Feb 03 '21 at 09:04
  • if unsigned short has the same number of value bits as signed long, the result is unsigned long, otherwise the result is signed long. – Antti Haapala -- Слава Україні Feb 03 '21 at 09:15

0 Answers0