Thread: Static functions

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    98

    Static functions

    Hi.

    A while ago, a wrote a function as part of a program, and unknowingly gave the function the same name as a function in one of the libraries I'd included. I got round the problem by declaring my function as 'static'.

    Since then, I now almost out of habit declare every one of my functions as static. Is this a bad thing to do? I don't really understand the implications of a static function.

    Thanks.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >Is this a bad thing to do?

    No. If functions are only used within a certain file, declare them such that they can only be accessed by functions in those file. Using static functions normally and non-static functions only when necessary usually results in a well structured program.

    The same counts for global variables. Don't use global variables too much, they can make a program hard to understand, debug and maintain. But if you need them, make them static when they are only use them in the file and non-static when used by other modules.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    98
    Thanks for the advice.

    Looks like I've accidentally been doing the right thing for once!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. LNK2001 ERROR!!! need help
    By lifeafterdeath in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2008, 05:05 PM
  3. Replies: 23
    Last Post: 07-09-2007, 04:49 AM
  4. Static functions.... why?
    By patricio2626 in forum C++ Programming
    Replies: 4
    Last Post: 04-02-2007, 08:06 PM
  5. Static variables and functions problem in a class
    By earth_angel in forum C++ Programming
    Replies: 16
    Last Post: 09-15-2005, 12:08 PM