Solved

Static funtions

Posted on 2000-03-15
8
322 Views
Last Modified: 2008-02-01
Hi
  Please explain me abt Static functions in C...
  Static variables which hold the values
with in the program,,But what is use with Static functions..

Is there static functions are available in C.. Ans is Yes then give me syntax and use of that functions with examples...


Thanks in advance
Mahesh
0
Comment
Question by:MaheshKP
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2619171
static functions can only be used in the .c module in which they are defined, they are not visible in other modules.
0
 

Author Comment

by:MaheshKP
ID: 2619192
Hi Rao
   What ur telling is Static functions are available in C , Just like static
variables..My understand is correct means give me a ex..
0
 
LVL 10

Accepted Solution

by:
rbr earned 5 total points
ID: 2619220
The static modifier is a little bit different between functions and variable and it also depends on the scope.
Example


a.c

static int a=1;

static int func1 (void)
{
    static int b=0;
    b+=a;
    return (b)  
}

func1 only can be called out of the source a.c. If you link another source with it func1 will be invisible from the other source. This is he mean of a static function.

Every time the func1 is called the variable b will be incremented. This is the mean of a  static variable within a function.

a can only be accessed within a.c. In another soure a extern int a will not work (or will use another variable).
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2619222
Actually, I'm not even sure they are avavilable in ANSI C (I do mostly C++) but  GCC thinks it is.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2619226
MaheshKP!

In C language static functions are used for code hiding: static functions defined in the module are visible in that module *only*, i.e. linker can't see they though any other "ordinary" function is visible for linker.

So static functions are useful in multimodule projects.

Andrew
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2619227
Example? just at the static keyword:

static void f()
{
   /*Ur code */
}


That's what I said, can only be used from the same module, isn't it?
0
 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2619235
KangaRoo, you are right.

Andrew
0
 

Author Comment

by:MaheshKP
ID: 2634982
ThanQ for all

Mahesh
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How do I test for current date? 9 95
How to organize data in excel ? 2 112
C++ vs C compilers 13 157
How to install SVN Command Line Client? 5 41
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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

911 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

21 Experts available now in Live!

Get 1:1 Help Now