fork(1) download
  1. #include <stdlib.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4.  
  5. int main() {
  6.  
  7. // Buffer.
  8. unsigned char buffer[sizeof(int) + sizeof(int) + sizeof(float)];
  9.  
  10. // Buffer pointer (first object).
  11. unsigned char *buf_ptr = buffer;
  12.  
  13. // Variables ressources.
  14. int a = 65500;
  15. int b = 32000;
  16. float c = 3.14;
  17.  
  18. // Variables pointers.
  19. int *aa = NULL;
  20. int *bb = NULL;
  21. float *cc = NULL;
  22.  
  23. /* Copy variables to buffer. */
  24. uint16_t cur = 0;
  25. memcpy(buf_ptr + cur, &a, sizeof(int));
  26. cur += sizeof(int);
  27. memcpy(buf_ptr + cur, &b, sizeof(int));
  28. cur += sizeof(int);
  29. memcpy(buf_ptr + cur, &c, sizeof(float));
  30. cur += sizeof(float);
  31.  
  32. /* Set pointers. */
  33. cur = 0;
  34. aa = (int*)(buf_ptr + cur);
  35. cur += sizeof(int);
  36. bb = (int*)(buf_ptr + cur);
  37. cur += sizeof(int);
  38. cc = (float*)(buf_ptr + cur);
  39. cur += sizeof(float);
  40.  
  41. // Print values.
  42. printf("%i %i %f\n", *aa, *bb, *cc);
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 2156KB
stdin
Standard input is empty
stdout
65500 32000 3.140000