Skip to content

Instantly share code, notes, and snippets.

@flatcap
Last active September 17, 2018 20:55
Show Gist options
  • Save flatcap/d3be59b0989f9a89d1b7a99d22c24923 to your computer and use it in GitHub Desktop.
Save flatcap/d3be59b0989f9a89d1b7a99d22c24923 to your computer and use it in GitHub Desktop.
inheritance
#include <stdio.h>
/* ---------------------------------- */
#define struct_Named \
char *name
struct Named
{
struct_Named;
};
/* ---------------------------------- */
struct Account;
#define struct_Account \
struct_Named; \
struct Account *next
struct Account
{
struct_Account;
};
/* ---------------------------------- */
struct ImapAccount
{
struct_Account;
int i;
};
struct PopAccount
{
struct_Account;
int p;
};
int main()
{
struct ImapAccount ia;
ia.name = "imap";
ia.next = NULL;
ia.i = 42;
struct PopAccount pa;
pa.name = "pop";
pa.next = NULL;
pa.p = 99;
printf ("%s, %d\n", ia.name, ia.i);
printf ("%s, %d\n", pa.name, pa.p);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment