fork(6) download
  1. #include <stdio.h>
  2. #include <assert.h>
  3.  
  4. int main()
  5. {
  6. // These are their sizes here. So just to prove it.
  7. assert(sizeof(char) == 1);
  8. assert(sizeof(short) == 2);
  9. assert(sizeof(float) == 4);
  10.  
  11. // Little endian
  12. union {
  13. short s;
  14. char c[2];
  15. } endian;
  16. endian.s = 0x00FF; // would be stored as FF 00 on little
  17. assert((char)endian.c[0] == (char)0xFF);
  18. assert((char)endian.c[1] == (char)0x00);
  19.  
  20. union {
  21. float f;
  22. unsigned char c[4];
  23. } var;
  24. var.f = 0.0003401360590942204;
  25. printf("%x %x %x %x\n", var.c[3], var.c[2], var.c[1], var.c[0]); // little endian
  26. return 0;
  27. }
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
39 b2 54 4a