| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | greatest common divisor |
PE> {
PE> temp = a;
PE> a = b;
PE> b = temp;
PE> }
FM> Couldn't you avoid using the temporary variable by replacing the above
FM> with
FM> {
FM> a ^= b;
FM> b ^= a;
FM> a ^= b;
FM> }
There is rarely any point, and a compelling reason NOT to do this - readability.
Any optimising compiler will use temp as a register variable in this
context - declare it 'register' within the inner block if you're concerned
about non-optimising compilers. The xor method would usually be slower
(than two MOV's and one XCHG) in that case.
This is one of those cute tricks you show off at parties, but not
recommended for any real code.
david
--- MaltEd/2 1.0.b6
* Origin: Unique Computing Pty Ltd (3:632/348)SEEN-BY: 3/1 2 4 5 6 50/99 54/54 99 620/243 623/630 632/103 301 348 365 386 SEEN-BY: 632/998 633/371 634/383 384 635/502 503 544 555 636/100 670/206 SEEN-BY: 711/401 409 430 807 808 809 932 934 712/623 627 713/888 714/906 SEEN-BY: 800/1 @PATH: 632/348 635/503 50/99 54/54 99 711/808 809 934 |
|
| 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™.