Created
February 12, 2022 12:02
-
-
Save dlOuOlb/e9e54ace3ed0b2a034d8abbe0af81fa6 to your computer and use it in GitHub Desktop.
A singleton example in C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "uSingleton.h" /* uSingleton */ | |
extern signed int main( void ) { return uSingleton.Method_( 0 ); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "uSingleton.h" /* uSingleton */ | |
static signed int xMethod_( const signed int Arg ) { return Arg; } | |
const struct uSingleton uSingleton = { xMethod_ }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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