Static variable or function parameter?

This is a discussion on Static variable or function parameter? within the C Programming forums, part of the General Programming Boards category; Hey everyone. I have a function where I need to uses a variable everytime the functions is called. I need ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    230

    Static variable or function parameter?

    Hey everyone. I have a function where I need to uses a variable everytime the functions is called. I need to know the value of the variable when the function is called. Which one is better: Static variable or just modify the variable before the function is called then pass it to the function?
    I'm not sure which one is better even for code-reuse. I want to make the code as re-usable as possible.

    Thanks

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,532
    Passing a parameter is better.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 01:17 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21