static function

static function

Post by predat » Mon, 19 Mar 2001 07:10:35



I don't understand what is difference between static and normal function?
eg :
static int gg(){
 printf("Hello world\n");

Quote:}

int gg1(){
  printf("Hello world\n");

Quote:}

--
signoff predator
 
 
 

static function

Post by Erik Max Franci » Mon, 19 Mar 2001 08:35:16



> I don't understand what is difference between static and normal
> function?

At module level, a static function is local to that module (e.g., source
file).  A non-static function is global.

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ The woman's movement is no longer a cause but a symptom.
\__/ Joan Didion
    Physics reference / http://www.alcyone.com/max/reference/physics/
 A physics reference.

 
 
 

static function

Post by Jens.Toerr.. » Mon, 19 Mar 2001 08:42:28



> I don't understand what is difference between static and normal function?
> eg :
> static int gg(){
>  printf("Hello world\n");
> }
> int gg1(){
>   printf("Hello world\n");
> }

Its local to the current file, i.e. if you have a project with more than
one file you can have a function with the same name (as long as they are
declared static) in each file without the linker getting upset.

                                            HTH, Jens
--
        _  _____  _____

    _  | |  | |    | |           AG Moebius, Institut fuer Molekuelphysik
   | |_| |  | |    | |           Fachbereich Physik, Freie Universitaet Berlin
    \___/ens|_|homs|_|oerring    Tel: ++49 (0)30 838 - 53394 / FAX: - 56046

 
 
 

static function

Post by predat » Mon, 19 Mar 2001 18:25:55



>Its local to the current file, i.e. if you have a project with more than
>one file you can have a function with the same name (as long as they are
>declared static) in each file without the linker getting upset.

Thank you both , I now understand why I should write modules with static
or without it :o)

--
signoff predator

 
 
 

static function

Post by Fletcher Glen » Wed, 21 Mar 2001 02:03:53


Applied to C++ classes, a normal function is only accessable
from an instance of the class that contains it.  A static function
is accessable from anywhere, but it cannot access the variables
specific to an instance of a class.   An example of a static
method would be a signal handler.  This is useful, because the
void * argument could be a pointer to a specific instance
of a class.

--
Fletcher Glenn
to reply remove NOSPAM from my reply address


Quote:

> I don't understand what is difference between static and normal function?
> eg :
> static int gg(){
>  printf("Hello world\n");
> }

> int gg1(){
>   printf("Hello world\n");
> }

> --
> signoff predator

 
 
 

static function

Post by Erik Max Franci » Wed, 21 Mar 2001 02:08:39



> Applied to C++ classes, a normal function is only accessable
> from an instance of the class that contains it.  A static function
> is accessable from anywhere, but it cannot access the variables
> specific to an instance of a class.   An example of a static
> method would be a signal handler.  This is useful, because the
> void * argument could be a pointer to a specific instance
> of a class.

Static member functions still don't have C linkage, unfortunately, so
for a signal handler you'd need a separate extern "C" function wrapping
around the static member function.

But it was pretty clear the original poster wasn't talking about this
C++ meaning of static, anyway.

--

 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Custom reconciles us to everything.
\__/ Edmund Burke
    Alcyone Systems' CatCam / http://www.catcam.com/
 What do your pets do all day while you're at work?  Find out.

 
 
 

1. static functions in library matching global functions

I have a peculiar problem which I'm sure you gurus can answer.

I've created a full-blown Motif widget for Solaris 2.5.1 and I've compiled
it into a dynamic shared library so that I can use it in multiple programs.

The problem is, however, that some of the static functions in the library
have the same names as public functions in the application that uses the
library, and at runtime the library calls the global functions instead of
its own static functions!

I thought that static stuff were renamed so that it would not be accessible
nor possibly match other functions. If, for instance, a static variables in
two object modules have the same name, how do the compiler know which one to
use, and when? But if functions are renamed, how come the application
manages to call the wrong functions?

Is the behavior perhaps different when compiling a library (I'm using cc
4.2)? Is there a switch I can use to make the library call the correct
static functions?

Please help, as I don't know how to solve this problem (other than the
obvious; renaming the functions, of course (which is not a good solution
since I can never be 100% sure whether some other program has global
functions with the same names...).

--
Ketil Hunn

2. Swap space distribution

3. static function

4. Linux Losers

5. Make gcc3.3 Eliminate Unused Static Functions

6. Windowdecoration in KDE3

7. ixj.c: EXPORT_SYMBOL of static functions

8. IP from Netbios

9. objdump -r a.o not giving static function call

10. "static declaration for `function' follows non-static"????

11. How to locate static variables declared inside a function?

12. dlsym/dladdr and functions declared "static"

13. hugetlb: make private functions static