Skip to content

Instantly share code, notes, and snippets.

@cfr
Forked from vlasovskikh/.hgignore
Created July 27, 2010 18:24
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 cfr/492623 to your computer and use it in GitHub Desktop.
Save cfr/492623 to your computer and use it in GitHub Desktop.
syntax:glob
main
*.o
typedef int Image;
Image *make_image(int foo);
char access_pixel(Image *img, int r, int c);
#include <stdlib.h>
#include <image.h>
typedef struct {
int foo, bar;
} IplImage;
Image *make_image(int foo) {
IplImage *img = (IplImage *) malloc(sizeof(IplImage));
if (!img)
return NULL;
img->foo = foo;
img->bar = foo + 14;
return (Image *) img;
}
char access_pixel(Image *img, int r, int c) {
IplImage *iplimg = (IplImage *) img;
return iplimg->foo + r + c;
}
#include <stdio.h>
#include <image.h>
int main() {
Image *img = make_image(42);
if (!img) {
fprintf(stderr, "error: querying an image for 42 failed\n");
return 1;
}
struct {
char c;
} a = {'a'};
printf("access_pixel(img, 0, 1) = %d\n", access_pixel(&a, 0, 0));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment