473,398 Members | 2,188 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,398 software developers and data experts.

What is the use of static functions in C lang?

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
11 1341

"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
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: porneL | last post by:
How do I use static functions/properties with inheritance? I've found it very problematic. class Foo { static function A() {/* ??? */::B(); } static function B() {echo 'Foo';} }; class...
24
by: Xah Lee | last post by:
in computer languages, often a function definition looks like this: subroutine f (x1, x2, ...) { variables ... do this or that } in advanced languages such as LISP family, it is not uncommon...
56
by: Xah Lee | last post by:
What are OOP's Jargons and Complexities Xah Lee, 20050128 The Rise of Classes, Methods, Objects In computer languages, often a function definition looks like this: subroutine f (x1, x2, ...)...
7
by: Nolan Martin | last post by:
is a static functions address constant? ie.. static void func(); write_to_file(&func); Restart program... static void func(); void (*funcPtr) ();
12
by: dual0 | last post by:
Hello, I found some function like void static foo(...){ .... } what does the static keyword stand for? what is a static function?
40
by: vishnu | last post by:
Hi friend, i have a problem in my program what is the use of static function in C lang? plz help me
3
by: Diebels | last post by:
Hi, I have some problems using static variables which results in a core dump. I have attached code and coredump to the end of my message. I am trying to implement a kind of factory design. I...
1
by: Markus Demetz | last post by:
Hi, I'm quite new to C++. I'm developing under Microsoft Visual Studio, andI've written some classes and want them to be exported to a .dll. I use a macro DLL_EXPORT and everything goes well....
2
by: frakie | last post by:
Hi 'body, I'm trying to compile a program which uses two static libraries. One is wrote in C language the other is wrote in C++ but it's functions are under extern "C" declaration. Once I try to...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.