Variable declaration in extended types

Previous topic - Next topic

MrTAToad

I've found that a program using a floating-point variable in an extended type will still compile even if the variable is access like an integer :

Code (glbasic) Select
TYPE TTest
a=5.7

FUNCTION test%:
DEBUG self.a%+"\n"
ENDFUNCTION
ENDTYPE

LOCAL y AS TTest

y.test()


a is defined as a float, but is accessed like its an integer (and the result is a floating-point value).

Do it in a standard function

Code (glbasic) Select
FUNCTION test%:
LOCAL a=5.7

DEBUG a%+"\n"
ENDFUNCTION


and you get a compiler error (which is correct).

MrTAToad

Thanks  =D  Gernot's not going to be happy  :)

Kitty Hello

Oh, I'm so happy. Soo happy. ... if I wasn't to implement extended types at all :/

I'll have a close look, though.

Moru

Well you did say you would regret it, didn't you? :-)

MrTAToad


bigsofty

If it's any consolation, I initially disliked them but now I really enjoy them now!
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Moebius

Not an extended types problem.  This compiles even with explicit decls. :
Code (glbasic) Select
FOR i = 1 TO 10; NEXT;
I think variables in FOR/NEXT loops are defined temporarily.  This doesn't work:
Code (glbasic) Select
FOR i = 1 TO 10; NEXT;
PRINT i, 10, 10
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

MrTAToad

Yes, I forgot about that - I'll delete my previous post  :whistle:

Silly me...