HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Typecast - why?

02-20-2009, 05:54 PM#1
Tyrande_ma3x
I've seen in some spells something like this:

Collapse JASS:
local Data d = Data.create()
local timer tim = CreateTimer()
...
set ht[tim] = integer(d) // Table attaching.
call TimerStart(...)

And then:

Collapse JASS:
local Data d = Data(ht[GetExpiredTimer()])
... etc.

My question is - why? I thought using normal struct references was enough (like set ht[tim] = d; local Data d = ht[GetExpiredTimer()]). More exactly, I'd like to know what is the purpouse of typecasting and does it have any specific usage with the example I provided; I can't seem to understand the explanation in jasshelpermanual. Thank you.
02-20-2009, 07:27 PM#2
Vexorian
Collapse JASS:
set ht[tim] = integer(d) // Table attaching
This is not necessary but it makes the code easier to undertand, it is more explicit that you are placing the struct's pointer in a place where an integer should go.

Collapse JASS:
local Data d = Data(ht[GetExpiredTimer()])
if ht[] returns a integer, this one really is necessary, the only reason that not doing the typecast compiles right in jasshelper is due to a limitation in jasshelper, that I wish to fix one day, this limitation is the cause of many ugly pitfalls that you don't want to get into when doing vJass.
02-20-2009, 08:03 PM#3
Anitarf
On a sidenote, those spells aren't the best code to learn from, since they apparently do such deprecated things as destroying timers.
02-21-2009, 08:50 AM#4
Tyrande_ma3x
I see. Thanks a lot for the explanation, Vex.
02-21-2009, 11:47 AM#5
Toadcop
btw... you should remove or fix the check for...

if "lol"=="lol" and MyStruct>0 then
endif

... aka if it's multiple condition (not only MyStruct>0) it will phail and say it's not allowed to match different "types". in fact it's lame cause it's integer and should be considered as integer in such cases. it's just a side note... (cause it's very anoying to type every time integer() )

well if you want to keep it add some preprocessor directive...

#no_fucking_stuff 1 // xD
02-21-2009, 11:57 AM#6
Vexorian
mystruct!=0 will work. Adding or not "lol"=="lol" won't change anything.

If when you use > there, an error appears, then god bless the compiler for preventing you from doing stupid things for no reason. When you use myStruct>0 you are doing a cardinal comparison with a non-cardinal type, and for no reason. The true idea to compare against 0 is to verify if it is null or not, so you got to use != or ==, it is absolute non-sense to use >.

Nobody sane cares if typing integer() is annoying or not (It is not), do you know what is really annoying ? Having run-time type mismatches that are not detected during compile time.

All struct pointers are integers but not all integers are struct pointers thinking otherwise is stupid. Or do you think that just because all handles are integers the opposite is true? Oh that causes the I2H bug, such tragedy...
02-21-2009, 12:55 PM#7
Toadcop
lol... you a talking shit related to jass.

structure can be also < 0 so your check will fail etc.
ahh well i understand vJass is concepted for lul coders... who doesnt care what in fact it's.

I2H bug - how does it fail ? O.o imo it's an overhyped shit like the rest. it only fails for the reason of bad concept of handle system (what it's possible to add to stack allready added handle) otherwise all this "problems" wouldnt exist. (+ it only fails if you operate with non existing objects otherwise it works with out any problem)

and i don't see any sense how integer can mess something up O_o so to forbidde < / > comparision...

your explanasion above is pure theorie (non jass related) shit =)
cause in generated jass code it will be integer...