Possible Duplicate:
How to create a Singleton in C ?
Hello, if I have a structure definition as follows:
struct singleton
{
char sharedData[256];
};
Can I impose the singleton pattern on instance variables of the above structure in C [not in C++]?
If you just forward declare your
structin the header file, it will be impossible for clients to create an instance of it. Then you can provide a getter function for your single instance.Something like this:
.h:.c: