| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | StringToInteger |
FM> Instead of a pointer, you could just declare the parameter FM> const. BL> Eh? What's the point of converting a constant to an integer? BL> I'd already know the answer. FM> You miss the point. Comprehensively, by the sound of it . FM> And I don't know if BP7 allows parameters to be declared as FM> const anyway. Look it up in Delphi to see what I mean. FM> Basically if you declare a parameter const it's not passed on FM> the stack but a pointer is passed (transparently to you). It FM> can do this because the compiler can check that you're not FM> modifying that string within the called function. Yair, BP7 allows constant parameters. I've just got the hang of using variables. while (s[i] > = '0') and (s[i] <= '9') do BL> That's how I started, and it's slower than the set. In fact, a BL> set was what I tried last... and it's the fastest of all. I BL> declared a constant set and it's slower! God only knows why. BL> Borland must do something fiendishly clever with their sets. I BL> love 'em. FM> OK, the generated code must have changed from TP6, that would FM> certainly be possible as the set handling code was fairly FM> atrocious there. Looks like I'll have to check out the code FM> from BP7 as I'm still surprised that it's faster than the 2 FM> tests. I'll let you know. Unfortunately I think my FM> dis-assembler only works on TP6 & TPW1.5 TPUs, so I'll have to FM> use the debugger. What was the time difference in your tests? I can't remember now, Frank, but it was appreciable 20-40%, say. Of course, that's half my loop anyway, so it was a big change. Ahhh... the book says something about using very efficient code in small sets. It talks about CMP inline instructions following the IN operator. Whatever that means. But it works. BL> Delphi has a StrToInt function. I'm in BP7. FM> You'd have the same problem. I suspected that StrToInt just FM> called Val and I was right. Here's the complete code for FM> StrToInt from the RTL source... The creeps! I imagined dwarves at Borland something like medieval monks copying the Bible in assembler language, and the rotten creeps just wrap a VAl() procedure! That really sux! BL> I've structured my string with the numbers upfront to reduce BL> the loop, and if it doesn't find any numbers it stops anyway. FM> That's not the point we're trying to cover here, it's the FM> opposite - what if your string contained *all* numbers, say FM> '1234'? Read above. It can't do that. This is not meant to be a general purpose StrToInt function. FM> You'd have a subtle bug which might not appear in your testing. FM> The chance (246/256) is that the string would be followed in FM> memory by a non-digit and you'd be right, mate. One day (or 10 FM> days out of 256) it would be followed by a digit and you'd end FM> up with for example 12349 as your answer. I know all this from personal experience. I am close to being the world champion at overflowing memory. I'm the one who did something with a pointer that ate the BC++ compiler! I challenge anyone to do that! You're not talking to a raw beginner here, Frank. I am an Olympic-class stuffup. FM> StrToInt wouldn't help you, see above. Pascal doesn't suck, it FM> evolves. I bet all that stuff will be in BP8 - August? I look forward to it. I'm reasonable fluent in Pascal now and I rather like it, but Delhi is noticeably nicer. All Delphi needs is a smile on Athena. FM> Now I just went and had a look at the (ASM) source for Val, and FM> it appears at a quick glance to step over leading spaces for FM> you anyway. But not other forms of whitespace. Does it? I didn't think it stepped over anything. It only works on pure numbers in the string, so you have to strip the string first. FM> It's a piece of piss. I might even do it for you if I'm bored. FM> After I've checked out the BP7 generated code for sets. If you're not bored I could come around and bore you. I'm nearly as boring as I am impolite with pointers. FM> instead of just doing "* 10" they do a series of shifts and FM> rotates through AX & DX. I know exactly how they feel. I get that way if I have a third Cointreau. Regards, Bob ___ Blue Wave/QWK v2.12 @EOT: ---* Origin: Precision Nonsense, Sydney (3:711/934.12) SEEN-BY: 633/267 270 @PATH: 711/934 809 808 50/99 635/544 727 633/267 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.