Click to See Complete Forum and Search --> : static keyword help


indiocolifa
March 17th, 2003, 10:28 AM
When programming with the Win32 API, when and where I should use the static keyword?

Why in many C Win32 samples user defined functions are defined as static? This is an obsolete method of old C win32 programming ?

Im programming in C++/W32 API with VC++ NET, not plain C, so i dont know if its necessary or not (my win32 programs work well without any STATIC definitions, except when I want a variable inside a function to retain values between calls).

thank you!

Paul McKenzie
March 17th, 2003, 11:31 AM
Originally posted by indiocolifa
When programming with the Win32 API, when and where I should use the static keyword?

Why in many C Win32 samples user defined functions are defined as static? This is an obsolete method of old C win32 programming ?No. A static function means that the function has file scope, i.e. it is not callable outside the file it is defined in, that's all. This has nothing to do with obsolescence, it's just the way the programmer decided to design their module.
Im programming in C++/W32 API with VC++ NET, not plain C, so i dont know if its necessary or notThis is a program design issue, not an API or compiler issue.(my win32 programs work well without any STATIC definitions, except when I want a variable inside a function to retain values between calls).
a) static variables are not the same as static functions.

b) There is nothing bad or good about using static, just like there is nothing bad or good about using new[] as opposed to declaring an array.

These are all program design issues, and are not related to any operating system, API, or language used.

Regards,

Paul McKenzie

indiocolifa
March 17th, 2003, 10:15 PM
thanks paul!

;)