fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct point1d {
  5. int x;
  6. void (*print)(void const *);
  7. };
  8.  
  9. struct point2d {
  10. int x, y;
  11. void (*print)(void const *);
  12. };
  13.  
  14. void print_point1d( void const * p ) {
  15. printf( "(%d)\n", ((struct point1d const*)p)->x );
  16. }
  17.  
  18. void print_point2d( void const * p ) {
  19. printf( "(%d, %d)\n", ((struct point2d const*)p)->x,
  20. ((struct point2d const*)p)->y );
  21. }
  22.  
  23. int main() {
  24. struct point1d p1 = { .x=1, .print=&print_point1d };
  25. struct point2d p2 = { .x=3, .y=4, .print=&print_point2d };
  26.  
  27. p1.print( &p1 );
  28. p2.print( &p2 );
  29. }
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
(1)
(3, 4)