Archive: Shortening the Asc macro (wiki/Asc)


Shortening the Asc macro (wiki/Asc)
  A very short question, really: I want to get the ascii-number of the first character of a string. so I've taken a look at the Asc macro on the wiki. But I'm wondering if it can be made shorter. Can I use

System::Call "*(&t1 r11)i.r11"

>System::Call "*$R1(&i1 .r11)"
Without creating memory leaks or whatnot? I'm skipping the System::Free command because I'm using only one variable now, but I'm not entirely sure if that's legal.


Edit: After discussion with Anders, I guess the above is indeed not correct. $R1 is made to point at some allocated memory, which is afterwards not freed. Should be:

System::Call "*(&t1 r12)i.r11"

>System::Call "*$11(&i1 .r12)"
>System::Free $R1
>

As Anders probably have noted, your first System::Call line allocates a buffer, so without System::Free memory will leak.

To do this without any allocation, you can use:

StrCpy $0 asdasd
Math::Script "r0 = c(r0[0])"
DetailPrint $0