Solved

Singleton pointer in C

Posted on 2011-03-24
8
1,665 Views
Last Modified: 2012-05-11
I came across some document stating Singleton pointers in C
what is this any example ?
0
Comment
Question by:tittu
  • 4
8 Comments
 
LVL 7

Expert Comment

by:Murugesan Nagarajan
Comment Utility
First, C is not suitable for OO programming. You'd be fighting all the way if you do. Secondly, singletons are just static variables with some encapsulation. So you can use a static global variable. However, global variables typically have far too many ills associated with them. You could otherwise use a function local static variable:

From the url:
[ur]
http://stackoverflow.com/questions/803673/how-to-create-a-singleton-in-c
[/ur]
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
>> First, C is not suitable for OO programming.

Even though I don't see how this is relevant to the question, I beg to differ. OO concepts have been used for professional C programming long before C++ existed. Sure, C++ added some syntactic conveniences etc., but the heart of OO can easily be followed in C (and it might even be a good idea to do so).


Anyway :

>> Secondly, singletons are just static variables with some encapsulation.

Scope or lifetime are not (directly) relevant to the concept of a singleton. Or in other words : a singleton doesn't need to be static.
The static keyword is often used to enforce certain aspects of a singleton implementation (specifically the one instance guarantee), but it is not required.


A singleton is simply a restriction that is placed on a type to have only one instance of it.

A "singleton pointer" is a less common term, so in order to be sure, I'd have to see the concept in which it is used. But I'd guess that it refers to a specific pointer type that should only have one instance. It's an odd idea, but maybe it makes sense in the specific case where it was used.
0
 

Author Comment

by:tittu
Comment Utility
array vs singleton pointer in coverity testing described in C please eloborate this
I knew single pointers and array issues an eloborated explanation is required..
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
Comment Utility
>> array vs singleton pointer in coverity testing described in C please eloborate this

In that case, I think it's a confusion of terms, and they actually mean a pointer that points to only one object, rather than an array of objects.
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
>> Not expected answers

It would have been nice if you could have said this earlier, instead of waiting 6 months.
It would also have been nice to tell us what you DID expect then, so we could adapt our answers.

As it stands now, a C grade is not acceptable. Either we didn't answer your question, and then you can give us an explanation of how we didn't answer your question, after which we can assist you further. Or we did answer your question, and then a grade higher than C seems appropriate.
0
 
LVL 53

Expert Comment

by:Infinity08
Comment Utility
>> instead of waiting 6 months.

I meant to say almost one month.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now