Skip to content

Instantly share code, notes, and snippets.

@dlOuOlb
Created February 12, 2022 12:02
Show Gist options
  • Save dlOuOlb/e9e54ace3ed0b2a034d8abbe0af81fa6 to your computer and use it in GitHub Desktop.
Save dlOuOlb/e9e54ace3ed0b2a034d8abbe0af81fa6 to your computer and use it in GitHub Desktop.
A singleton example in C.
#include "uSingleton.h" /* uSingleton */
extern signed int main( void ) { return uSingleton.Method_( 0 ); }
#include "uSingleton.h" /* uSingleton */
static signed int xMethod_( const signed int Arg ) { return Arg; }
const struct uSingleton uSingleton = { xMethod_ };
#if !__STDC__
# error A standard C compiler is required!
#elif defined(uSingleton)
#else
# define uSingleton uSingleton
extern const struct uSingleton { signed int (*const Method_) ( signed int Arg ); } uSingleton;
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment