113
C-Control Pro Mega Series
© 2008 Conrad Electronic
Visibility of Variables
When variables are declared outside of functions then they will have global visibility. I. e. they can be
addressed from every function. Variable declarations within functions produce local variables. Local
variables can only be reached within the function. An example:
Dim a,b As Integer
Sub func1()
Dim a,x,y As Integer
// global b is accessible
// global a is not accessible since concealed by local a
// local x,y is accessible
// u is not accessible since local to function main
End Sub
Sub main()
Dim u As Integer
// global a,b is accessible
// local u is accessible
// x,y u is not accessible since local to function main
End Sub
Global variables have a defined memory space which is available throughout the entire program run.
At program start the global variables will be initialized by zero.
Local variables will during calculation of a function be arranged on the stack. I. e. local variables
exist in memory only during the time period in which the function is executed.
If with local variables the same name is selected as with a global variable then the local variable will
conceal the global variable. While the program is working in the function where the identically named
variable has been defined the global variable cannot be addressed.
Static Variables
With local variables the property Static can be placed for the data type.
Sub func1()
Static a As Integer
End Sub
In opposition to normal local variables will static variables still keep their value even if the function is
left. At a further call-up of the function the static variable will have the same contents as when leaving
the function. In order to have the contents of a Static variable defined at first access the static
variables will equally to global variables at program start also be initialized by zero.
Содержание C-Control Pro Mega Series
Страница 1: ... 2008 Conrad Electronic C Control Pro Mega Series ...
Страница 9: ...VIII Inhalt 2008 Conrad Electronic ...
Страница 10: ...Part 1 ...
Страница 17: ...Part 2 ...
Страница 23: ...Part 3 ...
Страница 41: ...32 Hardware 2008 Conrad Electronic 3 3 5 3 Component Parts Plan ...
Страница 57: ...48 Hardware 2008 Conrad Electronic 3 4 5 3 Component Parts Plan ...
Страница 58: ...Part 4 ...
Страница 91: ...82 IDE 2008 Conrad Electronic ...
Страница 92: ...Part 5 ...
Страница 135: ...126 Compiler 2008 Conrad Electronic 31 1F US 63 3F 95 5F _ 127 7F DEL ...
Страница 136: ...Part 6 ...
Страница 231: ...Part 7 ...
Страница 240: ......