TIP: Click on subject to list as thread! ANSI
echo: aust_avtech
to: Roy Mcneill
from: Bob Lawrence
date: 1997-01-09 09:07:40
subject: For loops in C...

BL> I got all excited writing macros, but unless you use it lots,
 BL> you may as well just write it longhand a few times.

 RM> Complex macros in C are frowned on, they can almost always be
 RM> written in conventional code in the same space.

  This came out of a tight loop (zmodem?) where I was calling a
function in Pascal several times and Paul was using a macro... The
Pascal approach ran at HALF speed. When I changed my function to 
code written several times as you suggest, it was as fast as C and
five-times as messy. Calling the function was taking most of the time.

 RM> They're less great for code shorthand.

  It depends...

 PE> if (i == end)
 PE> {
 PE>  i = 0;
 PE> }
 PE> if (i == mid)
 PE> {
 PE>  finished = 1;
 PE> }
 
 BL> but I would have gone:
 
 BL>   if(i == end) i = 0;
 BL>   if(i == mid) finished = 1;

 RM> The "syntax" is identical.

  No... I left out the redundant curly brackets.

 RM> The "indenting" is different. Indenting to C people is like
 RM> religion to Northern Irish people.

  Yair... just another way to make it difficult to make sense of C.

 BL> To me, this shows the flow of logic better, and reveals that
 BL> you are testing for i unnecessarily in most cases.

  Did you notice that Paul only noticed he was testing unnecessarily
after I'd changed the layout?

Regards,
Bob
___ Blue Wave/QWK v2.12
@EOT:

---
* Origin: Precision Nonsense, Sydney (3:711/934.12)
SEEN-BY: 711/808 934 712/610
@PATH: 711/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™.