[ create a new paste ] login | about

Link: http://codepad.org/sAlHy19b    [ raw code | output | fork ]

C, pasted on Mar 2:
#include <stdio.h>

typedef struct client_ops_t client_ops_t;
typedef struct client_t client_t, *pno;

struct client_t {
    /* ... */
   int data;
    client_ops_t *ops;
};

struct client_ops_t {
    pno (*AddClient)(client_t *);
    pno (*SubClient)(client_t *);
};

pno AddClient (client_t *client);
pno SubClient (client_t *client);


///////////////////////////////////////////////////////////////////////////////

int main(void) {

   client_t c1;
   c1.data = 10;

   printf("data = %d\n", c1.data);

   c1.ops->AddClient(&c1);
   printf("data = %d\n", c1.data);

   //c1.ops->SubClient(&c1);
   printf("data = %d\n", c1.data);
   return 0;
}

///////////////////////////////////////////////////////////////////////////////



pno AddClient (client_t *client) {
   client->data += 1;
   return client;
}
pno SubClient (client_t *client) {
   client->data--;
   return client;
}


Output:
1
Segmentation fault


Create a new paste based on this one


Comments: