5 ms·
But a code based on several standards, not only on C standard. For example we know, that basic source character sets should contain space (C11 5.2.1), we know t
by m_kim 7y ago
But a code based on several standards, not only on C standard. For example we know, that basic source character sets should contain space (C11 5.2.1), we know that character constants has type "int" and that character constants represent value equal to the code of a symbol (C11 5.4.4). We know used source character set and we know code of the space character. We can configure specific source character set on the POSIX compatible systems. We know that return statement in the main function equivalent to the call to exit function (C11 5.1.2.2.3), we know that only 8 least significant bits will be used from returned value (POSIX.1-2001 definition of "exit"), we know that INT_MAX should be at least 32767 (C11 5.2.4.2.1) so we sure that the result that we got from "return" statement in the "main" function is positive integer from 0 to 512. Finally if we configure source character set to be sure that ' ' has code 32 we know for sure that we got value 416 in the specified example. So we know for sure answer on question 3 based on the C11, POSIX.1-2017, and ISO 646 standards.
- NieDzejkob 7y agoI don't know if POSIX specifies CHAR_MAX, but on most systems, storing the value into a char will change the value, making it everything but 416: https://tio.run/##S0oszvifnFiiYFeSWlyil6xgY@Pq7/Y/M69EITcxM0@jLD8zRVOhmktBITkjsUghUcFWQR0ItRQMja2BgkWpJaVFeQqJ1ly1/4H6uLjSk5MVICZx6ekn6uWXlnClJmfkK6jY/wcA https://tio.run/##S0oszvifnFiiYFeSWlyil6xgY@Pq7/Y/M69EITcxM0...
- deleted 7y ago[deleted]
- deleted 7y ago[deleted]
- m_kim 7y agoMy mistake: We have (32*13) with minimal possible CHAR_BIT is 8. So it either 416 for char bigger then eight bits, or 160 for unsigned eight bits char, or -96 for signed eight bits char. Then it extended to the signed integer value (one of this three values), and then we got result as (int)(status & 0377). For all three cases result will be 160.