Last active
December 20, 2022 21:44
-
-
Save RaniAgus/f04370fa2fe70a1af8aba6db1335a3c8 to your computer and use it in GitHub Desktop.
Numeros negativos y enteros sin signo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdint.h> | |
| #include <commons/memory.h> | |
| #define RUN(EXP) do { printf(#EXP); EXP; printf("\n"); } while(0) | |
| #define EVALUATE(EXP) do { printf(#EXP " => %s\n", (EXP) ? "true" : "false"); } while(0) | |
| int main() { | |
| RUN(mem_hexdump(&(int){ -1 }, sizeof(int))); | |
| RUN(mem_hexdump(&(int16_t){ -1 }, sizeof(int16_t))); | |
| RUN(mem_hexdump(&(uint16_t){ -1 }, sizeof(uint16_t))); | |
| RUN(mem_hexdump(&(uint16_t) { UINT16_MAX }, sizeof UINT16_MAX)); | |
| EVALUATE(-1 == -1); | |
| EVALUATE(-1 == (int16_t)-1); | |
| EVALUATE(-1 == (uint16_t)-1); | |
| EVALUATE(-1 == UINT16_MAX); | |
| printf("\n"); | |
| EVALUATE((int16_t)-1 == -1); | |
| EVALUATE((int16_t)-1 == (int16_t)-1); | |
| EVALUATE((int16_t)-1 == (uint16_t)-1); | |
| EVALUATE((int16_t)-1 == UINT16_MAX); | |
| printf("\n"); | |
| EVALUATE((uint16_t)-1 == -1); | |
| EVALUATE((uint16_t)-1 == (int16_t)-1); | |
| EVALUATE((uint16_t)-1 == (uint16_t)-1); | |
| EVALUATE((uint16_t)-1 == UINT16_MAX); | |
| printf("\n"); | |
| EVALUATE(UINT16_MAX == -1); | |
| EVALUATE(UINT16_MAX == (int16_t)-1); | |
| EVALUATE(UINT16_MAX == (uint16_t)-1); | |
| EVALUATE(UINT16_MAX == UINT16_MAX); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mem_hexdump(&(int){ -1 }, sizeof(int)) | |
| 0x00000000: ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 |................| | |
| mem_hexdump(&(int16_t){ -1 }, sizeof(int16_t)) | |
| 0x00000000: ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| | |
| mem_hexdump(&(uint16_t){ -1 }, sizeof(uint16_t)) | |
| 0x00000000: ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| | |
| mem_hexdump(&(uint16_t) { UINT16_MAX }, sizeof UINT16_MAX) | |
| 0x00000000: ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 |................| | |
| -1 == -1 => true | |
| -1 == (int16_t)-1 => true | |
| -1 == (uint16_t)-1 => false | |
| -1 == UINT16_MAX => false | |
| (int16_t)-1 == -1 => true | |
| (int16_t)-1 == (int16_t)-1 => true | |
| (int16_t)-1 == (uint16_t)-1 => false | |
| (int16_t)-1 == UINT16_MAX => false | |
| (uint16_t)-1 == -1 => false | |
| (uint16_t)-1 == (int16_t)-1 => false | |
| (uint16_t)-1 == (uint16_t)-1 => true | |
| (uint16_t)-1 == UINT16_MAX => true | |
| UINT16_MAX == -1 => false | |
| UINT16_MAX == (int16_t)-1 => false | |
| UINT16_MAX == (uint16_t)-1 => true | |
| UINT16_MAX == UINT16_MAX => true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment