Old 28th November 2007, 13:11   #1
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
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
PHP Code:
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:
PHP Code:
System::Call "*(&t1 r12)i.r11"
System::Call "*$11(&i1 .r12)"
System::Free $R1 

Last edited by MSG; 28th November 2007 at 14:36.
MSG is offline   Reply With Quote
Old 28th November 2007, 21:21   #2
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
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:
code:
StrCpy $0 asdasd
Math::Script "r0 = c(r0[0])"
DetailPrint $0


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump