Results 1 to 5 of 5

Thread: static functions

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112

    static functions

    alright so i understand how a static variable works..but i dont understand how a static function works..i cant find any clear info on it..does anyone have a nice smart way of explaining it?
    thanks

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    static functions like static variables have class scope but are independent of objects, so declaring a function static within a class disables its access to the object variables, which is of course good if you don't need them (as it doesn't need an object and you call the function with classname::functionname).
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Or.

    Volatile functions are 'created' on the fly. The arguments are pushed on the stack, the function's variables are initialized, the function is executed, return values are pushed onto the stack and all of the functions variables are destroyed, along with any associated stack space. Memory efficient.

    If a function calls another function, then all variables, the local stack & stack pointers, register contents are all pushed onto the stack, then destroyed. This invokes execessive stack use for nested functions that are called from different places.

    Static functions are never dereferenced (destroyed). Neither are the variables. Static functions hold onto more memory at the start, but depending on what the program is doing, may be faster.
    But, if you have multiple entry points into the static function you can introduce bugs.

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Aren't you refering to static local variables jim? if not then thats something i didn't know.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yep, jim's confusing things here.

    Anyway, if it's not within class scope, a static function is simply only available withing the source file it is defined in.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width