fork(1) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stddef.h>
  4.  
  5. typedef struct __attribute__((packed))
  6. {
  7. char a;
  8. short b;
  9. int c;
  10. } my_struct;
  11.  
  12. char buff[50];
  13.  
  14. int main(void) {
  15. my_struct s;
  16. s.a = 1;
  17. s.b = 2;
  18. s.c = 3;
  19.  
  20. memcpy(buff, &s, sizeof(s));
  21.  
  22. short *p = (short *)&buff[offsetof(my_struct, b)];
  23. *p = 1337;
  24.  
  25. printf("%d\r\n", *p);
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0s 5516KB
stdin
Standard input is empty
stdout
1337