Posts: 60
Threads: 8
Joined: Jan 2005
What is the difference between the two symbols "=" and "=>" for initializing variables?
Code:
dim as integer n = 2
dim as integer m => 3
? n, m
According to my tests, they seem to be equivalent.
Posts: 658
Threads: 71
Joined: Sep 2003
dim j as string * 10 = "hello"
url]http://fbide.sourceforge.net/[/url]
Posts: 1,407
Threads: 117
Joined: Dec 2002
The fist one is executed at run time.
With the second one you tell the compiler to intialize the variable when it makes the place for it, so at run time the data is already in.
Antoni
Posts: 922
Threads: 15
Joined: Jun 2003
=> was just added to resolve the ambiguities as Von showed, because FB allows constant expressions to be used when declaring fixed-len or zstring's (unlike QB). "dim s as string * 1 = "ab"" would be seen as "dim s as string * (1 = "ab")".
Posts: 1,956
Threads: 65
Joined: Jun 2003
Quote:The fist one is executed at run time.
With the second one you tell the compiler to intialize the variable when it makes the place for it, so at run time the data is already in.
Let me understand this, Antoni.
For the first one:
DIM AS INTEGER N = 2
This would be the equivalent to these 2 lines in QB: Right?
DIM N AS INTEGER
N = 2
For the second one:
DIM AS INTEGER M => 3
I cannot find an equivalent in QB. The closest would be to use a CONST, but although M is initialized to 3 when the program is loaded, M can be modified at runtime, whereas a CONST cannot. Am I right?
*****
Posts: 658
Threads: 71
Joined: Sep 2003
they are the same.
di i as integer {= | => } some value
it's only needed when you define fixed lenght string.
dim i as string * 10 = "hello"
this will give you an error, couse you can do arithmetic operations there. so string * 10 => "hello" is needed.
dim j as integer = 10 = 10
you'll get integer value to be -1 rather then 10.
and there was no such thing as var initalisers in qb.
url]http://fbide.sourceforge.net/[/url]
Posts: 1,956
Threads: 65
Joined: Jun 2003
Von,
You say "they are the same". Does that mean that Antoni's observations are not true?
Sorry, I get lost in your examples.
Please establish the rules first, and then follow with examples.
And for this thread, please don't mix examples with STRING. The original question of this thread dealt with DIM AS INTEGER.
Thanks.
*****
Posts: 658
Threads: 71
Joined: Sep 2003
i used String to clearify why it was needed.
dim i as integer = 10
dim i as integer => 10
are completely the same.
BUT why was => needed is this:
dim i as string * 10 => "some value"
compiler would see it otherwise as: * (10="some value") or as in C: * (10=="some value"). meaning it would compare 10 firts to "some value" -what cannot be done becouse of non matching types.
url]http://fbide.sourceforge.net/[/url]
Posts: 1,956
Threads: 65
Joined: Jun 2003
Thanks, Von, I think I get it now.
dim i as integer = 10
dim i as integer => 10
are completely the same.
AND, THE INTEGER I IS SET TO 10 AT RUNTIME, I ASSUME.
*****
Posts: 658
Threads: 71
Joined: Sep 2003
it's evulated at the compile time.
url]http://fbide.sourceforge.net/[/url]