Skip to content

Instantly share code, notes, and snippets.

@sw17ch
Created February 15, 2012 04:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sw17ch/1833197 to your computer and use it in GitHub Desktop.
Save sw17ch/1833197 to your computer and use it in GitHub Desktop.
bad_way.c
#include "interface.h"
void initialize(void)
{
puts("Common Initialize\n");
#if defined(PLATFORM_A)
puts("Initialize A\n");
#elif defined(PLATFORM_B)
puts("Initialize B\n");
#else
#error "Invalid platform."
#endif
}
void do_stuff(void)
{
puts("Common Do Stuff\n");
#if defined(PLATFORM_A)
puts("Do Stuff A\n");
#elif defined(PLATFORM_B)
puts("Do Stuff B\n");
#else
#error "Invalid platform."
#endif
}
void cleanup(void)
{
puts("Common Cleanup\n");
#if defined(PLATFORM_A)
puts("Cleanup A\n");
#elif defined(PLATFORM_B)
puts("Cleanup B\n");
#else
#error "Invalid platform."
#endif
}
#include <stdio.h>
#include "common.h"
void common_initialize(void)
{
puts("Common Initialize\n");
}
void common_do_stuff(void)
{
puts("Common Do Stuff\n");
}
void common_cleanup(void)
{
puts("Common Cleanup\n");
}
#ifndef __COMMON__
#define __COMMON__
void common_initialize(void);
void common_do_stuff(void);
void common_cleanup(void);
#endif /* __COMMON__ */
#ifndef __INTERFACE__
#define __INTERFACE__
void initialize(void);
void do_stuff(void);
void cleanup(void);
#endif /* __INTERFACE__ */
#include "interface.h"
int main(int argc, char * argv[])
{
initialize();
do_stuff();
cleanup();
return 0;
}
#include <stdio.h>
#include "common.h"
#include "interface.h"
void initialize(void)
{
common_initialize();
puts("Initialize A\n");
}
void do_stuff(void)
{
common_do_stuff();
puts("Do Stuff A\n");
}
void cleanup(void)
{
common_cleanup();
puts("Cleanup A\n");
}
#include <stdio.h>
#include "common.h"
#include "interface.h"
void initialize(void)
{
common_initialize();
puts("Initialize B\n");
}
void do_stuff(void)
{
common_do_stuff();
puts("Do Stuff B\n");
}
void cleanup(void)
{
common_cleanup();
puts("Cleanup B\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment