By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,434 Members | 1,854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,434 IT Pros & Developers. It's quick & easy.

What is the use of static functions in C lang?

P: n/a
Hi friend,

what is the use of static functions in c lang? How it can useful to our
programs?
plz help me.

Nov 15 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a

"sabarish" <su******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi friend,

what is the use of static functions in c lang? How it can useful to our
programs?
plz help me.


See the answers you already got.

-Mike
Nov 15 '05 #2

P: n/a
On 11 Nov 2005 10:43:15 -0800, in comp.lang.c , "sabarish"
<su******@gmail.com> wrote:
Hi friend,

what is the use of static functions in c lang? How it can useful to our
programs?


"static" restricts the scope of the function to the current file. In
other words, you can't see it from another part of your code.

This is useful for protecting operations which should be private.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #3

P: n/a
It is recommended that all private functions be declared as static.
With 'static', others can tell at first sight that the function is a
private function - used only by other functions in the same file, but
not by functions in other files. Considering the .c file as an
"implementation" and the corresponding .h file as an "interface", the
programmer prototypes the private functions in the .c and the public
functions in the .h. Of course the definitions of both types of
functions are in the .c file.

Nov 15 '05 #4

P: n/a
Mike Wahler wrote:
"sabarish" <su******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hi friend,

what is the use of static functions in c lang? How it can useful to our
programs?
plz help me.


See the answers you already got.


This is the second poster asking the same question. They must have the
same professor and the same homework to do...
Nov 15 '05 #5

P: n/a
Charles Richmond wrote:
Mike Wahler wrote:

"sabarish" <su******@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googleg roups.com...
Hi friend,

what is the use of static functions in c lang? How it can useful to our
programs?
plz help me.


See the answers you already got.

This is the second poster asking the same question. They must have the
same professor and the same homework to do...

More likely just an automated troller.

If you look you'll see the same questions asked over and over
under numerous names.

Probably by someone who scans these newsgroups to collect
names to be added to the list that they sell to bulk-emailers.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 15 '05 #6

P: n/a
Mark McIntyre wrote:
On 11 Nov 2005 10:43:15 -0800, in comp.lang.c , "sabarish"
<su******@gmail.com> wrote:

Hi friend,

what is the use of static functions in c lang? How it can useful to our
programs?

"static" restricts the scope of the function to the current file. In
other words, you can't see it from another part of your code.

This is useful for protecting operations which should be private.


Am I the only one who thinks that static should have been local? To me,
the word local makes more sense. Just a thought.

Joe
Nov 16 '05 #7

P: n/a
Joe Estock <je*****@NOSPAMnutextonline.com> writes:
Am I the only one who thinks that static should have been local? To me,
the word local makes more sense. Just a thought.


The word "static" has so many meanings in C that no one word is
going to be a meaningful substitute in every situation.
--
"What is appropriate for the master is not appropriate for the novice.
You must understand the Tao before transcending structure."
--The Tao of Programming
Nov 16 '05 #8

P: n/a
On 2005-11-16, Ben Pfaff <bl*@cs.stanford.edu> wrote:
Joe Estock <je*****@NOSPAMnutextonline.com> writes:
Am I the only one who thinks that static should have been local? To me,
the word local makes more sense. Just a thought.


The word "static" has so many meanings in C that no one word is
going to be a meaningful substitute in every situation.


Maybe having a single word with all those meanings was a mistake.
Nov 16 '05 #9

P: n/a
Ben Pfaff wrote:
Joe Estock <je*****@NOSPAMnutextonline.com> writes:

Am I the only one who thinks that static should have been local? To me,
the word local makes more sense. Just a thought.

The word "static" has so many meanings in C that no one word is
going to be a meaningful substitute in every situation.


So many? I think "static" qualifier has precisely two meanings in C. One
as a storage class and one to suppress external linkage. What are some
of the others?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 17 '05 #10

P: n/a
Joe Wright <jw*****@comcast.net> writes:
Ben Pfaff wrote:
Joe Estock <je*****@NOSPAMnutextonline.com> writes:
Am I the only one who thinks that static should have been local? To
me, the word local makes more sense. Just a thought.

The word "static" has so many meanings in C that no one word is
going to be a meaningful substitute in every situation.


So many? I think "static" qualifier has precisely two meanings in
C. One as a storage class and one to suppress external linkage. What
are some of the others?


C99 adds a new use of "static" in array parameter declarations.
See C99 6.7.5.3p7.

An example given in the standard is

void f(double a[restrict static 3][5]);

which "specifies that the argument corresponding to a in any call to f
must be a non-null pointer to the first of at least three arrays of 5
doubles".

--
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.
Nov 17 '05 #11

P: n/a
Joe Wright wrote:
Ben Pfaff wrote:
Joe Estock <je*****@NOSPAMnutextonline.com> writes:

Am I the only one who thinks that static should have been local? To
me, the word local makes more sense. Just a thought.


The word "static" has so many meanings in C that no one word is
going to be a meaningful substitute in every situation.

So many? I think "static" qualifier has precisely two meanings in C. One
as a storage class and one to suppress external linkage. What are some
of the others?


The problem is that these meanings (three, actually, if you count the
new feature in C99) are only this simple if you think in C, instead of
in terms of the problems you're trying to solve. "Storage class"?
"External linkage"? What planet are these C programmers from, anyway?

static int a;
int b;

void f(int c[static 10]) {
static int d;
int e;
...
}

"Now, you see, the first 'static' means that 'a' has internal linkage,
that is, you can't reference it from other units, unlike 'b'. Of course
'b' has static storage duration, just like 'a', so they're both
initialized to 0.

'c' is a static array argument, in this case, a static array with at
least 10 elements. You don't need to use this, but your program may get
faster if you do. If you use this you must always pass an array with at
least that many elements. 'c' does not have static storage duration, of
course.

'd' is local to 'f', just like 'e' (and 'c', of course), but unlike 'e',
the value of 'd' will be remembered across function calls. 'd' has
static storage duration, like 'b', so it will be automatically
initalized, but 'e' will not.

Got that? Good. And now, C++."

S.
Nov 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.