EnableTypeCheck/DisableTypeCheck/TypeChange()
Posted: Thu Sep 03, 2015 4:52 pm
At the moment there is no typecheck at all.
for example
all work without problems. My opionion is, that this should be forbidden. Because this would break nearly every code in PureBasic, i suggest to add some new directives like EnableExplicit.
EnableTypeCheck
Enables the check, all examples above would cause a compiler-error
DisableTypeCheck
normal actual handling
TypeChange(variable/pointer, type/structure/interface)
Tells the compiler, that he should ignore here the original type of the variable/pointer and change it here to the given type. To change the type to a pointer, just start type with a *.
Maybe "ConvertType" is a better name?
Above Example:
Importent for Structures/Interfaces:
Should work too. Why? Because all elements in T1 are in T2 at the same place, so it is not a Problem, when the program access it with the T1-Structure.
Same for Interfaces.
for example
Code: Select all
Structure T1
a.b
b.b
EndStructure
Define *pointer1.string,*pointer2.long,double.d,struc.t1
*pointer1=@double.d
*pointer2=@t1
*pointer2=*pointer1
double=t1
EnableTypeCheck
Enables the check, all examples above would cause a compiler-error
DisableTypeCheck
normal actual handling
TypeChange(variable/pointer, type/structure/interface)
Tells the compiler, that he should ignore here the original type of the variable/pointer and change it here to the given type. To change the type to a pointer, just start type with a *.
Maybe "ConvertType" is a better name?
Above Example:
Code: Select all
EnableTypeCheck
Structure T1
a.b
b.b
EndStructure
Define *pointer1.string,*pointer2.long,double.d,struc.t1
*pointer1=TypeChange(@double.d,*string)
*pointer2=TypeChange(@t1,*long)
*pointer2=TypeChange(*pointer1,*long)
double=TypeChange(t1,d)
Code: Select all
EnableTypeCheck
Structure T1
a.b
EndStructure
Structure T2 extends T1
b.b
endstructure
define *pointer.t1, var.t2
*pointer=@var
Same for Interfaces.