fork(2) download
  1. #include <stdio.h>
  2. #include <stddef.h>
  3.  
  4. typedef struct {
  5. long long ll;
  6. int i;
  7. short s;
  8. char ch1;
  9. char ch2;
  10. } Tipo;
  11.  
  12. int main(void) {
  13. Tipo var = { .ll = 1000000000000, .i = 1000, .s = 10, .ch1 = 'a', .ch2 = 's' };
  14. printf("%lld\n", var.ll);
  15. printf("%i\n", var.i);
  16. printf("%d\n", var.s);
  17. printf("%c\n", var.ch1);
  18. printf("%c\n", var.ch2);
  19. printf("%lld\n", *((long long*)(((char*)&var) + offsetof(Tipo, ll))));
  20. printf("%i\n", *((int*)(((char*)&var) + offsetof(Tipo, i))));
  21. printf("%d\n", *((short*)(((char*)&var) + offsetof(Tipo, s))));
  22. printf("%c\n", *((char*)(((char*)&var) + offsetof(Tipo, ch1))));
  23. printf("%c\n", *((char*)(((char*)&var) + offsetof(Tipo, ch2))));
  24. }
  25.  
  26. //http://pt.stackoverflow.com/q/183287/101
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
1000000000000
1000
10
a
s
1000000000000
1000
10
a
s