fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4.  
  5. #define LONG_DBL_BYTES (80 / 8)
  6.  
  7. static void dump(void *data, size_t length)
  8. {
  9. for (size_t i = 0; i < length; i++) {
  10. printf("%.2x ", ((uint8_t *) data)[i]);
  11. }
  12. putchar('\n');
  13. }
  14.  
  15. int main(void) {
  16. long double number = 1.0;
  17.  
  18. printf("sizeof(long double) = %zu (%zu padding bytes)\n",
  19. sizeof(long double), sizeof(long double) - LONG_DBL_BYTES);
  20.  
  21. printf("Unmodified representation of %Lf:\n", number);
  22. dump(&number, sizeof(number));
  23.  
  24. // Patch unused (padding) bytes.
  25. memset(((uint8_t *) &number) + LONG_DBL_BYTES, 0xaa,
  26. sizeof(long double) - LONG_DBL_BYTES);
  27.  
  28. printf("After patching unused (padding) bytes of %Lf with 0xaa:\n",
  29. number);
  30. dump(&number, sizeof(number));
  31.  
  32. number += 2.0;
  33.  
  34. printf("Unused bytes are not touched when doing math on %Lf:\n",
  35. number);
  36. dump(&number, sizeof(number));
  37. }
  38.  
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
sizeof(long double) = 16 (6 padding bytes)
Unmodified representation of 1.000000:
00 00 00 00 00 00 00 80 ff 3f 00 00 00 00 00 00 
After patching unused (padding) bytes of 1.000000 with 0xaa:
00 00 00 00 00 00 00 80 ff 3f aa aa aa aa aa aa 
Unused bytes are not touched when doing math on 3.000000:
00 00 00 00 00 00 00 c0 00 40 aa aa aa aa aa aa