fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3.  
  4. typedef struct
  5. {
  6. void* userData;
  7. float (*value)(void*, int);
  8. } IA;
  9.  
  10. float get_float_from_uint16(void* userData, int index)
  11. {
  12. return ((uint16_t*) userData)[index];
  13. }
  14.  
  15. int main()
  16. {
  17. uint16_t bytes[] = {1, 2, 3, 4, 5 };
  18. IA a = {bytes, &get_float_from_uint16};
  19.  
  20. int index = 0;
  21. float f = a.value(a.userData, index);
  22. printf("%f\n", f);
  23. }
  24.  
  25.  
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
1.000000