little question about replaceable variable

Troll-Brain

You can change this now in User CP.
Reaction score
85
Because naming a local same as a global with a different type allowed to typecast in previous patches (return bug), i can't find the post i've created for it on wc3c.net months ago (wc3c research is lame and i have no valid result with "H2I" and "Troll-Brain" with google.
It's more tricky to use the return bug like that, but anyway the return bug is pointless now, and my method was supposed to create huge leaks (not tested).

JassHelper rename the local variable for you, else the map won't start.

EDIT : Meh, i've found this :

http://bbs.islga.org/read.php?tid=8722

In order to know if it still works (which i really doubt) you have to manually edit the map script war3map.j
 

the Immortal

I know, I know...
Reaction score
51
That's
not
typecasting!

Shadowing is whenever you declare a variable in a given scope (this case - a local function variable) with the same name as a var in an outer scope (in this case - a global var). And it doesn't matter whether they are of the same type - whatever you do with that variable, will be done with the local one, not with the 'shadowed' one. And that's exactly what the OP was referring to.

Typecasting is really a different thing - that's when you convert from one type to another. But this case isn't such. The value of the local 'a' variable has -nothing- to do with the value of the global one. And vice versa - after the function's exit, the global a won't be changed at all. That's what H2I was doing, for ex.

Also, if you have a CPP compiler (and who doesn't have one? -.-) :
Code:
#include<iostream>

char i = 65;

void sub()
{
    int i = 94;
    std::cout<<i<<" "<<sizeof(i)<<"\n";
}

int main()
{
    std::cout<<i<<" "<<sizeof(i)<<"\n";
    sub();
    std::cout<<i<<" "<<sizeof(i)<<"\n";
    return 0;
}
You'll see that first it shows a char with size 1 byte (= 8bit). In sub() function we introduce an int with the same name, and when we print it, you can clearly see that it's an integer with size 4 bytes (= 32bit). When we leave the sub() function, nothing has changed with the original var - prints exactly the same line as the first.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Meh, i don't own the vocabulary but i mean you could, in the past, typecast with shadowing variables but with different type.
Sorry if i wasn't clear.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top