Miscellaneous > Programming & Networking

Global Variables & Return 0

(1/1)

rtgwbmsr:
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:

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?
--- End quote ---


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.

--- End 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.

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

rtgwbmsr:

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.
--- End quote ---


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 ]

Navigation

[0] Message Index

Go to full version