--
PatrickSmyth - 24 Sep 2006
The following code example was presented at the
BioInformatics? weekly research meeting held on September 18, 2006 as an example of a coding technique to introduce Object Oriented like concepts into C.
a.h
typedef a_str = void *;
#ifndef EXTERN external
#define EXTERN external
#endif
EXTERN int
new_a(....);
EXTERN
int increment_a(a-str, err_code*);
a.c
#define EXTERN
#include a.h;
struct a
{
/*
Create a flag to see if the program is using our pseudo-class
*/
int magic = 0x1A1C;
// other attributes
}
EXTERN int new_a(a_str * ret_a, err_code *)
{
a* ret = malloc(size_of(a));
ret_a = (void *) ret;
}
EXTERN int increment_a (a_str* ret_a, err_code *)
{
if (ret_a == null)
// error
a* internal_a = (a*) ret_a;
if (a->magic <> 0x1A1C)
// error
}
EXTERN int delete_a ( a_str*)
{
a->magic = 0x0;
}