Skip to content

Instantly share code, notes, and snippets.

@dilfish
Created September 1, 2014 14:49
Show Gist options
  • Save dilfish/cc2af3f6620b84c009d9 to your computer and use it in GitHub Desktop.
Save dilfish/cc2af3f6620b84c009d9 to your computer and use it in GitHub Desktop.
nanomsg 里的 nn_pipe 是这样的
// Let's see Mr Sustrik's masterpiece
// He must like hierarchy and cleanness to death.
// So he defined an empty struct of nn_pipe to represent a
// concept of connection.
// I've known this trick for a while and never thought it could
// be used like this
// Sean at Shaanxi
// 20140901
// test for nanomsg.nn_pipe
#include <stdio.h>
struct nn_pipe;
struct nn_pipebase {
int i;
};
int
test_pipe(struct nn_pipe *p) {
struct nn_pipebase *pb = NULL;
pb = (struct nn_pipebase*)p;
printf("pb is %d\n", pb->i);
return 0;
}
int
test(void) {
struct nn_pipebase b;
b.i = 3;
test_pipe((struct nn_pipe*)&b);
return 0;
}
int
main(int argc, char **argv) {
test();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment