Skip to content

Instantly share code, notes, and snippets.

@dwilliamson
Created July 14, 2014 20:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwilliamson/8f35212fe81b097b3b50 to your computer and use it in GitHub Desktop.
Save dwilliamson/8f35212fe81b097b3b50 to your computer and use it in GitHub Desktop.
namespace api
{
namespace blah
{
// Opaque handle to the type this namespace exposes functions for
struct Blah;
// Lifetime management (malloc/free with construct/destruct)
Blah* New(u32 param);
void Delete(Blah* blah);
// 'Blah' API
void DoSomething(Blah* blah, u32 param);
u32 GetSomething(const Blah* blah);
}
// Bring the opaque handle into the API namespace
using blah::Blah;
}
#include "Blah.h"
int main()
{
api::Blah* blah = api::blah::New(2);
// All remaining work can be done with Koenig Lookup (ADR)
DoSomething(blah, 1);
u32 x = GetSomething(blah);
Delete(blah);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment