Author Topic: Global Variables & Return 0  (Read 2448 times)

rtgwbmsr

  • VIP
  • Member
  • ***
  • Posts: 1,257
  • Kudos: 0
    • http://www.akgames.net
Global Variables & Return 0
« on: 1 November 2002, 02:10 »
One thing I never really questioned (I swear!), but thought it might be good to ask is: are using Global Variables OK if you are using the variable in practically every function?

Also, what's with return 0;? I've never used it and never had a problem.

[ October 31, 2002: Message edited by: The_Muffin_Man/B0b ]


voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
Global Variables & Return 0
« Reply #1 on: 1 November 2002, 02:34 »
quote:
Originally posted by The_Muffin_Man/B0b:
One thing I never really questioned (I swear!), but thought it might be good to ask is: are using Global Variables OK if you are using the variable in practically every function?


Global variables are "cheating". That's why I make liberal use of them.        But actually you should try not to use them and if you are a developer in a software company your code just may not pass code inspection if you have global variables. And you may just be assigned to create specific modules, in which case you wouldn't be at liberty to use global variables. And your code will be more modular if you use local variables (the code in your functions/modules can be used in other programs and not be dependant on global variable names). Especially important if you want to make a "library" of functions.

   
quote:

Also, what's with return 0;? I've never used it and never had a problem.



I could be wrong but I think the compiler will add the equivelant of a "return 0" on all functions including main if you do not specify it. I may be talking out of my arse on this one though. Let me know if you find out differently.

[ October 31, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...

rtgwbmsr

  • VIP
  • Member
  • ***
  • Posts: 1,257
  • Kudos: 0
    • http://www.akgames.net
Global Variables & Return 0
« Reply #2 on: 1 November 2002, 02:37 »
quote:
I could be wrong but I think the compiler will add the equivelant of a "return 0" on all functions including main if you do not specify it. I may be talking out of my arse on this one though. Let me know if you find out differently.


You are right, at least for Borland. And yes, I am forced to program in Winblows. I asked them if I could bring in a laptop with Linux and they said no. It was a security risk, and my teacher needs to be able to run my programs in Winblows.

FUCKING-FAN-TASTIC

Just more icing on the cake   :mad:

[ October 31, 2002: Message edited by: The_Muffin_Man/B0b ]