Skip to content

Instantly share code, notes, and snippets.

@jonwingfield
Created February 5, 2016 14:11
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 jonwingfield/dd35f99b3a5f98975a86 to your computer and use it in GitHub Desktop.
Save jonwingfield/dd35f99b3a5f98975a86 to your computer and use it in GitHub Desktop.
Example C Wrapper for a C++ Class
#ifdef __cplusplus
#define CCALL extern "C"
CCALL RF24* rf24_init(uint8_t ce_pin, uint8_t cs_pin) { return new RF24(ce_pin, cs_pin); }
CCALL void rf24_begin(RF24* rf24) { rf24->begin(); }
CCALL void rf24_free(RF24* rf24) { delete rf24; }
#else
typedef struct {} RF24;
RF24* rf24_init(uint8_t ce_pin, uint8_t cs_pin);
void rf24_begin(RF24* rf24);
void rf24_free(RF24* rf24);
#endif
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment