473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Regarding Static

Hi All,

Pls clarify me what is the difference between static member and static
method in c.
pls some one reply me with Example.

Mar 8 '06 #1
9 1596
In article <11**********************@p10g2000cwp.googlegroups .com>,
sonu <sa****************@gmail.com> wrote:
Pls clarify me what is the difference between static member and static
method in c.


There is no difference, since neither exists. Perhaps you were thinking
of C++ or Java?

-- Richard
Mar 8 '06 #2
Hi Richard, is this any different in c ONLY

Mar 8 '06 #3
sonu wrote:
Hi Richard, is this any different in c ONLY


Is *what* any different in "c ONLY"???

Quote what and who you're replying to. See
<http://cfaj.freeshell.org/google/>

Looking at your original post, and Richard's reply, I can't quite see
why you didn't understand the answer (or you didn't understand the
question?). To try to re-phrase it for you:

The things you mention (static members and static methods) do not exist
in C programming language (as standardised by ISO/ANSI). They do,
however, exist in C++ (an entirely different kettle of fish) and Java
(more obviously so). These languages are off-topic in this newsgroup,
and you should re-direct your question to comp.lang.c++ or
comp.lang.java.

--
BR, Vladimir

Mar 8 '06 #4
In article <11*********************@j33g2000cwa.googlegroups. com>,
sonu <sa****************@gmail.com> wrote:
Hi Richard, is this any different in c ONLY


As I said, static members and methods don't exist in C. They are
things that exist in some object oriented languages such as Java and
C++.

-- Richard
Mar 8 '06 #5
sonu wrote:
Hi All,

Pls clarify me what is the difference between static member and static
method in c.
pls some one reply me with Example.


You're thinking of C++, not C. Followups set to comp.lang.c++.

My C++ is still a bit weak, so don't consider this to be authoritative.
Static members and static methods do not belong to a particular class
instance, and are not referenced through a particular class instance.
Instead, you refer to them using the class name and scope resolution
operator ::. The best way to illustrate it is with an example:

#include <iostream>

using std::cout;
using std::endl;

class MyClass
{
public:

MyClass()
{
m_staticInstance++;
}

~MyClass()
{
m_staticInstance--;
}

// Instance method
int getInstanceValue()
{
return m_instance;
}

// Static method
static void setStaticInstance(int value)
{
m_staticInstance = value;
}

// Instance member
int m_instance;

// Static member
static int m_staticInstance;
};

// If you declare a static member inside of a
// class, you must provide a corresponding
// definition of it outside of the class;
// this is necessary since the member
// has to exist independently
// of any class instance.

int MyClass::m_staticInstance = 0;

int main(void)
{
MyClass instance0, instance1;

// Refer to instance members and methods through
// the instance.

instance0.m_instance = 100;
instance1.m_instance = 200;

cout << "instance0.m_instance: "
<< instance0.m_instance << endl
<< "instance1.m_instance: "
<< instance1.m_instance << endl
<< "instance0.getInstanceValue(): "
<< instance0.getInstanceValue() << endl
<< "instance1.getInstanceValue(): "
<< instance1.getInstanceValue() << endl;
// Refer to static members and methods through
// the class name.
cout << "MyClass::m_staticInstance: "
<< MyClass::m_staticInstance << endl
<< "MyClass::getStaticInstance(): "
<< MyClass::m_staticInstance << endl;

MyClass::m_staticInstance = 3;

// Refer to static members and methods through
// the class name.
cout << "MyClass::m_staticInstance: "
<< MyClass::m_staticInstance << endl
<< "MyClass::getStaticInstance(): "
<< MyClass::m_staticInstance << endl;

return 0;
}

And the output:

john@marvin ~/prototypes/C++/static_demo $ ./static_demo
instance0.m_instance: 100
instance1.m_instance: 200
instance0.getInstanceValue(): 100
instance1.getInstanceValue(): 200
MyClass::m_staticInstance: 2
MyClass::getStaticInstance(): 2
MyClass::m_staticInstance: 3
MyClass::getStaticInstance(): 3

Mar 8 '06 #6
John Bode wrote:
sonu wrote:
Hi All,

Pls clarify me what is the difference between static member and
static method in c.
pls some one reply me with Example.


You're thinking of C++, not C. Followups set to comp.lang.c++.

For future occasions, be sure to crosspost as well as set follow-ups in
these situations. As it is, you posted a bunch of C++ that won't be
seen in clc++ unless someone replies, in which case they'll have no
idea what the original message was.


Brian

Mar 8 '06 #7

Default User wrote:
John Bode wrote:
sonu wrote:
Hi All,

Pls clarify me what is the difference between static member and
static method in c.
pls some one reply me with Example.
You're thinking of C++, not C. Followups set to comp.lang.c++.

For future occasions, be sure to crosspost as well as set follow-ups in
these situations. As it is, you posted a bunch of C++ that won't be
seen in clc++ unless someone replies, in which case they'll have no
idea what the original message was.

I still seem to be missing something or probably did not sleep well
yesterday. Isn't the OP talking of static variables in C ? Or is it
just me who is halucinating ?

Static variables do exist in C. If you have a static variable inside a
function the lifetime of the variable is till the life of the program.

I know you guys (and gals) know that but am I still missing something ?


Brian


Mar 9 '06 #8
"Jaspreet" <js***********@gmail.com> writes:
Default User wrote:
John Bode wrote:
> sonu wrote:
> > Hi All,
> >
> > Pls clarify me what is the difference between static member and
> > static method in c.
> >
> >
> > pls some one reply me with Example.
>
> You're thinking of C++, not C. Followups set to comp.lang.c++.

For future occasions, be sure to crosspost as well as set follow-ups in
these situations. As it is, you posted a bunch of C++ that won't be
seen in clc++ unless someone replies, in which case they'll have no
idea what the original message was.

I still seem to be missing something or probably did not sleep well
yesterday. Isn't the OP talking of static variables in C ? Or is it
just me who is halucinating ?


The OP asked about "static members" (in C, only structs have members,
and they can't be static) and "static methods" (C doesn't have
anything called "methods"; object-oriented languages often do).

If he wants to ask about static variables, he can certainly come back
here and do so (or read his C textbook).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 9 '06 #9

Keith Thompson wrote:
"Jaspreet" <js***********@gmail.com> writes:
Default User wrote:
John Bode wrote:
> sonu wrote:
> > Hi All,
> >
> > Pls clarify me what is the difference between static member and
> > static method in c.
> >
> >
> > pls some one reply me with Example.
>
> You're thinking of C++, not C. Followups set to comp.lang.c++.
For future occasions, be sure to crosspost as well as set follow-ups in
these situations. As it is, you posted a bunch of C++ that won't be
seen in clc++ unless someone replies, in which case they'll have no
idea what the original message was.

I still seem to be missing something or probably did not sleep well
yesterday. Isn't the OP talking of static variables in C ? Or is it
just me who is halucinating ?


The OP asked about "static members" (in C, only structs have members,
and they can't be static) and "static methods" (C doesn't have
anything called "methods"; object-oriented languages often do).

If he wants to ask about static variables, he can certainly come back
here and do so (or read his C textbook).

--

Thanks Keith for letting me know I am in my senses today. :) Yeah, let
the OP come back with his version of the question rather than we making
any assumptions on the exact query he wanted to ask.

Mar 9 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: raghavendra | last post by:
Hi , A static member can be accessed only by another static method....but the vice-versa is not true....Can anyone pls explain me the logic behind this... Also in a project, if we have too many...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
2
by: djinni | last post by:
howdy, Can anyone tell me where the function name string is stored when __func__ is used? I read that it is basically like declaring a static const char, but when I compile the following code,...
2
by: John Smith | last post by:
Hi, I have a question regarding the initialisation of aggregates: The C (99) standard states: section 6.7.8, paragraph 21 states: If there are fewer initializers in a brace-enclosed list than...
2
by: Suresh Kumar Rathod | last post by:
HI friends... Can any body give reason / logic behind static varable lifetime through out the process execution. i.e how does compiler maintains the static varable life through out the process...
2
by: palani12kumar | last post by:
can you please clear my doubt regarding static variables? at the time of declaring a static variable, is it compulsary to declare its data type? that is.... instead of writing "static int a;",...
1
by: wizwx | last post by:
I just noticed an interesting implementation of Singleton from Bruce Eckel's "Thinking in C++" vol. 2, pp 620: class Singleton { static Singleton s; public: static Singleton& instance() {...
8
by: somenath | last post by:
Hi All, I have a doubt regarding the pointer assignment . Please have a look at the following program . #include<stdio.h> #include<stdlib.h> #define NAMESIZE 10 #define SAFE_FREE(t) if(t)\...
1
by: subhalalitha | last post by:
There is a requirement in our system. There is one Transaction Monitoring thread which wakes up after every 30 sec and checks for the requests that didnot get responses for "2 min" and sends...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.