Skip to content

Instantly share code, notes, and snippets.

@tafryn
Last active December 14, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tafryn/5034232 to your computer and use it in GitHub Desktop.
Save tafryn/5034232 to your computer and use it in GitHub Desktop.
#include <stdio.h>
struct {
int first;
int second;
}typedef myStruct;
int getFirst (myStruct* a) { return (*a).first; }
int getSecond (myStruct* a) { return (*a).second; }
int sum(myStruct* a, myStruct* b, int (*pt2Func)(myStruct*)) {
int result = pt2Func(a) + pt2Func(b);
return result;
}
void main() {
myStruct sOne = {1,2};
myStruct sTwo = {10,100};
printf("Sum First: %d\n", sum(&sOne, &sTwo, &getFirst));
printf("Sum Second: %d\n", sum(&sOne, &sTwo, &getSecond));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment