fork(2) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct two_values
  6. {
  7. int some;
  8. char value;
  9. };
  10.  
  11. int main(void) {
  12. int some = 5;
  13. char value = 'a';
  14. unsigned char *data = malloc(sizeof(struct two_values));
  15. memcpy(data, &some, sizeof(int));
  16. memcpy(data+sizeof(int), &value, sizeof(char));
  17. struct two_values dest;
  18. memcpy(&dest, data, sizeof(struct two_values));
  19. printf("some = %d, value = %c\n", dest.some, dest.value);
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
some = 5, value = a